home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWFrame.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  78.3 KB  |  2,534 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFrame.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWFRAME_H
  13. #include "FWFrame.h"
  14. #endif
  15.  
  16. #ifndef FWPART_H
  17. #include "FWPart.h"
  18. #endif
  19.  
  20. #ifndef FWPRESEN_H
  21. #include "FWPresen.h"
  22. #endif
  23.  
  24. #ifndef FWPRTITE_H
  25. #include "FWPrtIte.h"
  26. #endif
  27.  
  28. #ifndef FWPRHDLR_H
  29. #include "FWPrHdlr.h"
  30. #endif
  31.  
  32. #ifndef FWCLPCMD_H
  33. #include "FWClpCmd.h"
  34. #endif
  35.  
  36. #ifndef FWSELECT_H
  37. #include "FWSelect.h"
  38. #endif
  39.  
  40. #ifndef FWMNUBAR_H
  41. #include "FWMnuBar.h"
  42. #endif
  43.  
  44. #ifndef SLMACOS_H
  45. #include "SLMacOS.h"
  46. #endif
  47.  
  48. #ifndef FWFLOWIN_H
  49. #include "FWFloWin.h"
  50. #endif
  51.  
  52. #ifndef FWODGEOM_H
  53. #include "FWODGeom.h"
  54. #endif
  55.  
  56. #ifndef FWITERS_H
  57. #include "FWIters.h"
  58. #endif
  59.  
  60. #ifndef FWVIEWAS_H
  61. #include "FWViewAs.h"
  62. #endif
  63.  
  64. #ifndef FWCURSOR_H
  65. #include "FWCursor.h"
  66. #endif
  67.  
  68. #ifndef FWBARRAY_H
  69. #include "FWBArray.h"
  70. #endif
  71.  
  72. #ifndef FWSCROLR_H
  73. #include "FWScrolr.h"
  74. #endif
  75.  
  76. #ifndef FWCNTRHW_H
  77. #include "FWCntrHW.h"
  78. #endif
  79.  
  80. #ifndef FWUTIL_H
  81. #include "FWUtil.h"
  82. #endif
  83.  
  84. #ifndef FWIDLE_H
  85. #include "FWIdle.h"
  86. #endif
  87.  
  88. #ifndef FWCONTXT_H
  89. #include "FWContxt.h"
  90. #endif
  91.  
  92. #ifndef FWRESOUR_H
  93. #include "FWResour.h"
  94. #endif
  95.  
  96. #ifndef FWRGNSHP_H
  97. #include "FWRgnShp.h"
  98. #endif
  99.  
  100. #ifndef FWLNKMGR_H
  101. #include "FWLnkMgr.h"
  102. #endif
  103.  
  104. #ifndef FWEVENTU_H
  105. #include "FWEventU.h"
  106. #endif
  107.  
  108. #ifndef SLODFSTR_H
  109. #include "SLODFStr.h"
  110. #endif
  111.  
  112. #ifndef SLODFSTR_K
  113. #include "SLODFStr.k"
  114. #endif
  115.  
  116. #ifndef FWSESION_H
  117. #include "FWSesion.h"
  118. #endif
  119.  
  120. #ifndef SLREGION_H
  121. #include "SLRegion.h"
  122. #endif
  123.  
  124. #ifndef FWSOMENV_H
  125. #include "FWSOMEnv.h"
  126. #endif
  127.  
  128. // ----- OpenDoc Includes -----
  129.  
  130. #ifndef SOM_ODArbitrator_xh
  131. #include <Arbitrat.xh>
  132. #endif
  133.  
  134. #ifndef SOM_ODStorageUnitView_xh
  135. #include <SUView.xh>
  136. #endif
  137.  
  138. #ifndef SOM_ODClipboard_xh
  139. #include <Clipbd.xh>
  140. #endif
  141.  
  142. #ifndef SOM_ODFocusSet_xh
  143. #include <FocusSet.xh>
  144. #endif
  145.  
  146. //========================================================================================
  147. // RunTime Info
  148. //========================================================================================
  149.  
  150. #ifdef FW_BUILD_MAC
  151. #pragma segment FW_FrameSegment
  152. #endif
  153.  
  154. //========================================================================================
  155. //    Template Instantiations
  156. //========================================================================================
  157.  
  158. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CFrame)
  159. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CFrame)
  160.  
  161. #ifdef FW_USE_TEMPLATE_PRAGMAS
  162.  
  163. #pragma template_access public
  164. #pragma template FW_TOrderedCollection<FW_CFrame>
  165. #pragma template FW_TOrderedCollectionIterator<FW_CFrame>
  166.  
  167. #endif
  168.  
  169. //========================================================================================
  170. //    Constant
  171. //========================================================================================
  172.  
  173. typedef long FW_FrameVersion;
  174. const FW_FrameVersion FW_kFrameVersion = 0;
  175.  
  176. //========================================================================================
  177. //    class FW_CFrame
  178. //========================================================================================
  179.  
  180. FW_DEFINE_AUTO(FW_CFrame)
  181. FW_DEFINE_CLASS_M1(FW_CFrame, FW_CSuperView)
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    FW_CFrame::FW_CFrame
  185. //----------------------------------------------------------------------------------------
  186.  
  187. FW_CFrame::FW_CFrame(Environment *ev,
  188.                     ODFrame* odFrame, 
  189.                     FW_CPresentation* presentation, 
  190.                     FW_CPart* part) :
  191.     FW_CSuperView(ev),        
  192.     fFrameID(odFrame->GetID(ev)),
  193.     fODFrame(odFrame),
  194.     fPart(part),
  195.     fContentView(NULL),
  196.     fGetFrontClicks(TRUE),
  197.     fNeedsFoci(FALSE),
  198.     fNeedsScrollingFocus(FALSE),
  199.     fHasSelectionFocus(FALSE),
  200.     fHasScrollingFocus(FALSE),
  201.     fActiveFacet(NULL),
  202.     fCanBeActiveFrame(TRUE),    
  203.     fPresentation(presentation),
  204.     fWindow(NULL),
  205.     fFacetCount(0),
  206.     fPreviousViewType(odFrame->GetViewType(ev)),
  207.     fViewAs(NULL),
  208.     fIdler(NULL),
  209.     fDraggable(NULL),
  210.     fDroppable(NULL),
  211.     fScroller(NULL),    
  212.     fViewUnderCursor(NULL),
  213.     fRequestedFrame(FALSE),    
  214.     fInSharedWindow(FALSE),
  215. #ifdef FW_BUILD_WIN
  216.     fShadowWindow(NULL),
  217. #endif    
  218.     fInternalTransformRealigmentNeeded(FALSE),
  219.     fContentViewOffset(FW_kZeroPoint),
  220.     fSubViewsCreated(FALSE),
  221.     fSourceFrame(this),
  222.     fDroppableState(FW_kFrameDroppable),
  223.     fInfoCommandAdjusted(false),
  224.     fShowPaletteOnMouseUp(FALSE),
  225.     fContentShape(NULL),
  226.     fAdoptsContainerProperties(FALSE)
  227. {
  228.     FW_ASSERT(fODFrame);
  229.     FW_ASSERT(fPart != NULL);
  230.     
  231.     // Frame is the default target of the event handling chain
  232.     // (it will be the Content View later if one is created)
  233.     fTarget = this;
  234.     
  235.     this->SetNextEventHandler(ev, part);
  236.  
  237.     fNeedsFoci = odFrame->IsRoot(ev);
  238.     
  239.     // ----- force to be view as frame if root -----
  240.     // [HLX] I don't use ChangeViewType because I don't want to be notified
  241.     if (fPreviousViewType != FW_CPart::fgViewAsFrameToken && IsRoot(ev))
  242.         fODFrame->SetViewType(ev, FW_CPart::fgViewAsFrameToken);
  243.  
  244.     // ----- Set the frame's view Bounds to its shape bounds
  245.     FW_CRect frameRect;
  246.     PrivGetFrameShapeBounds(ev, frameRect);
  247.     PrivSetBounds(ev, frameRect);
  248.     PrivSetExtent(ev, frameRect.Size());    
  249.  
  250.     // ----- By default the frame is the ContentView
  251.     fContentView = (FW_CSuperView*)this;
  252.     
  253.     FW_END_CONSTRUCTOR
  254. }
  255.  
  256. //----------------------------------------------------------------------------------------
  257. //    FW_CFrame::~FW_CFrame
  258. //----------------------------------------------------------------------------------------
  259.  
  260. FW_CFrame::~FW_CFrame()
  261. {
  262.     FW_START_DESTRUCTOR
  263.  
  264.     FW_SOMEnvironment ev;
  265.     
  266.     FW_ASSERT(fIdler == NULL);    // subclass must delete idler it created
  267.  
  268.     FW_ASSERT(fWindow == NULL);    // should have been deleted in FrameRemoved
  269.     
  270.     if (fViewAs && fPresentation)
  271.         fPresentation->PrivReleaseViewAs(fViewAs);
  272.  
  273.     // Delete first all subviews before deleting the scroller. 
  274.     DeleteSubViews(ev);
  275.     
  276.     // Now I can delete the scroller (if any)    
  277.     delete fScroller;
  278.     
  279.     if (fContentShape)
  280.     {
  281.         fContentShape->Release(ev);
  282.         fContentShape = NULL;
  283.     }
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. //    FW_CFrame::FrameRemoved
  288. //----------------------------------------------------------------------------------------
  289. // Notification
  290.  
  291. void FW_CFrame::FrameRemoved(Environment* ev, FW_Boolean toStorage)
  292. {
  293. FW_UNUSED(toStorage);
  294.  
  295. //    if (toStorage && fIdler)    [LSD] why this test?
  296.     if (fIdler)
  297.         fIdler->UnregisterIdle(ev);
  298.         
  299.     // ----- Relinquish what ever focus we have
  300.     RelinquishFocusSet(ev);
  301.         
  302.     // ----- Check that the window has been deleted -----
  303.     FW_ASSERT(fFacetCount == 0);    
  304.     FW_ASSERT(fWindow == NULL);    // When the frame is removed it should not have any facets. fWindow
  305.                                 // should already be null (see FacetRemoved)
  306.     
  307.     fODFrame = NULL;            // Don't have an ODFFrame anymore
  308. }
  309.  
  310. //----------------------------------------------------------------------------------------
  311. //    FW_CFrame::FrameAdded
  312. //----------------------------------------------------------------------------------------
  313. // Notification
  314.  
  315. void FW_CFrame::FrameAdded(Environment* ev, ODFrame* odFrame, FW_Boolean fromStorage)
  316. {
  317. FW_UNUSED(fromStorage);
  318.         
  319.     // In the case of frame in a shared window fODFrame can be NULL
  320.     FW_ASSERT(fODFrame == odFrame || fODFrame == NULL);
  321.     fODFrame = odFrame;
  322.     
  323.     // ----- Add it to the presentation -----
  324.     fPresentation->PrivAddFrame(ev, this);
  325.     
  326.     // ----- set up the last active frame ------
  327.     if (fPart->GetLastActiveFrame(ev) == NULL)
  328.     {
  329.         ODFocusSet* focusSet = GetFocusSet(ev);
  330.         if (focusSet && focusSet->Contains(ev, FW_CPart::fgSelectionFocusToken))
  331.             fPart->PrivSetLastActiveFrame(this);
  332.     }
  333.  
  334.     // ----- Initialize printing handler -----
  335.     FW_CPrintHandler* printHandler = NewPrintHandler(ev);
  336.     if (printHandler != NULL)
  337.         AdoptEventHandler(ev, printHandler);
  338. }
  339.  
  340. //----------------------------------------------------------------------------------------
  341. // FW_CFrame::GetTarget
  342. //----------------------------------------------------------------------------------------
  343.  
  344. FW_MEventHandler* FW_CFrame::GetTarget(Environment* ev) const
  345. {
  346. FW_UNUSED(ev);
  347.     return fTarget;
  348. }
  349.  
  350. //----------------------------------------------------------------------------------------
  351. // FW_CFrame::SetTarget
  352. //----------------------------------------------------------------------------------------
  353.  
  354. void FW_CFrame::SetTarget(Environment* ev, FW_MEventHandler* newTarget, FW_Boolean tabSelection)
  355. {
  356. FW_UNUSED(ev);
  357.     FW_ASSERT(newTarget);    // should never set the target to NULL
  358.         
  359.     if (fTarget != newTarget)
  360.     {
  361.         if (fHasSelectionFocus)
  362.             fTarget->DeactivateTarget(ev);
  363.         
  364.         fTarget = newTarget;
  365.         
  366.         if (fHasSelectionFocus)
  367.             fTarget->ActivateTarget(ev, tabSelection);
  368.     }
  369. }
  370.  
  371. //----------------------------------------------------------------------------------------
  372. // FW_CFrame::WantsToBeTarget
  373. //----------------------------------------------------------------------------------------
  374.  
  375. FW_Boolean FW_CFrame::WantsToBeTarget(Environment* ev)
  376. {
  377. FW_UNUSED(ev);
  378.     return true;
  379. }
  380.  
  381. //----------------------------------------------------------------------------------------
  382. //    FW_CFrame::HandleMenu
  383. //----------------------------------------------------------------------------------------
  384.  
  385. FW_Handled FW_CFrame::HandleMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  386. {
  387.     FW_Handled result = FW_kHandled;
  388.     FW_CClipboardCommand* cmd;
  389.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  390.     
  391.     switch (commandID)
  392.     {
  393.         case kODCommandViewAsWin:
  394.             GetPart(ev)->OpenPartWindow(ev, this, NULL);
  395.             break;
  396.         
  397.         case kODCommandCut:
  398.         case kODCommandCopy:
  399.         case kODCommandPaste:
  400.         case kODCommandPasteAs:
  401.         case kODCommandClear:
  402.             cmd = this->NewClipboardCommand(ev, commandID);
  403.             if (cmd)
  404.                 cmd->Execute(ev);
  405.             break;
  406.                         
  407.         case kODCommandSelectAll:
  408.             FW_CSelection* selection = fPresentation->GetSelection(ev);
  409.             if (selection)
  410.                 selection->SelectAll(ev);
  411.             break;
  412.             
  413.         case kODCommandGetPartInfo:
  414.             ShowPartInfo(ev);    // Link info or selection info
  415.             break;
  416.             
  417.         default:
  418.             result = FW_CSuperView::HandleMenu(ev, theMenuEvent);    
  419.     }
  420.     
  421.     return result;
  422. }
  423.  
  424. //----------------------------------------------------------------------------------------
  425. //    FW_CFrame::HandleVirtualKey
  426. //----------------------------------------------------------------------------------------
  427.  
  428. FW_Handled FW_CFrame::HandleVirtualKey(Environment* ev, const FW_CVirtualKeyEvent& theVirtualKeyEvent)
  429. {
  430.     FW_Handled handled = FW_MEventHandler::HandleVirtualKey(ev, theVirtualKeyEvent);
  431.     
  432.     if ((handled == FW_kNotHandled) && fScroller)
  433.         handled = fScroller->HandlePageNavigationKeys(ev, theVirtualKeyEvent);
  434.     
  435.     return handled;
  436. }
  437.  
  438. //----------------------------------------------------------------------------------------
  439. //    FW_CFrame::NewPartWindow
  440. //----------------------------------------------------------------------------------------
  441.  
  442. FW_CWindow* FW_CFrame::NewPartWindow(Environment* ev, 
  443.                                     const FW_CRect& suggestedWindowRect, 
  444.                                     const FW_CString& suggestedWindowTitle)
  445. {
  446.     return new FW_CWindow(ev, 
  447.                         fPart,
  448.                         fODFrame,
  449.                         FALSE,                            // persistent frame
  450.                         FW_CPart::fgViewAsFrameToken,
  451.                         GetPresentation(ev),            // Open it with the same presentation
  452.                         suggestedWindowTitle,
  453.                         suggestedWindowRect.Size(),
  454.                         suggestedWindowRect.TopLeft(),
  455.                         FW_kDocumentWindow);
  456. }
  457.  
  458. //----------------------------------------------------------------------------------------
  459. //    FW_CFrame::NewClipboardCommand
  460. //----------------------------------------------------------------------------------------
  461.  
  462. FW_CClipboardCommand* FW_CFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  463. {
  464. FW_UNUSED(ev);
  465. FW_UNUSED(commandID);
  466.     // [LSD] removed the assert to be more flexible in Form's CEditCmd class
  467.     //         user should check the return value before calling command->Execute(ev) 
  468. //    FW_DEBUG_MESSAGE("Your need to override FW_CFrame::NewClipboardCommand to create a command");
  469.     return NULL;
  470. }
  471.  
  472. //----------------------------------------------------------------------------------------
  473. // FW_CFrame::ShowPartInfo
  474. //----------------------------------------------------------------------------------------
  475. FW_Handled FW_CFrame::ShowPartInfo(Environment* ev)
  476. {
  477.     FW_Handled handledIt = FW_kNotHandled;
  478.  
  479.     if (GetPart(ev)->GetLinkManager(ev) != NULL)
  480.         if (GetPart(ev)->GetLinkManager(ev)->ShowLinkInfo(ev, this))
  481.             handledIt = FW_kHandled;
  482.  
  483.     if (!handledIt)
  484.     {
  485.         FW_CSelection* selection = fPresentation->GetSelection(ev);
  486.         if (selection)
  487.             handledIt = selection->ShowSelectionInfo(ev);
  488.     }
  489.  
  490.     return handledIt;
  491. }
  492.  
  493. //----------------------------------------------------------------------------------------
  494. //    FW_CFrame::InstallMenus
  495. //----------------------------------------------------------------------------------------
  496. //     By default call the part with the part menuBar
  497.  
  498. void FW_CFrame::InstallMenus(Environment *ev)
  499. {
  500.     GetPart(ev)->InstallMenus(ev, GetPart(ev)->GetMenuBar(ev));
  501. }
  502.  
  503. #ifdef FW_BUILD_MAC
  504. //----------------------------------------------------------------------------------------
  505. //    FW_CFrame::HandleWindowEvent
  506. //----------------------------------------------------------------------------------------
  507.  
  508. FW_Handled FW_CFrame::HandleWindowEvent(Environment* ev, const FW_CMacWindowEvent& windowEvent)
  509. {
  510.     FW_Handled handled = FW_kHandled;
  511.     
  512.     unsigned long message = windowEvent.GetMessage();
  513.     switch (windowEvent.GetMessage())
  514.     {
  515.         case inZoomIn:
  516.         case inZoomOut:
  517.             {    
  518.                 ODPlatformWindow platformWindow = GetWindow(ev)->GetPlatformWindow(ev);
  519.                 
  520.                 // ----- Get the size of the window border -----
  521.                 FW_CRect borderSize;
  522.                 FW_PlatformError error;
  523.                 FW_GetWindowBorderSize(platformWindow, borderSize, &error);
  524.                 FW_FailOnError(error);
  525.                 
  526.                 // ----- Find out where the window would like to be zoomed out to 
  527.                 FW_CRect screenRect;
  528.                 ::FW_MacGetMaxIntersectedDevice(platformWindow, screenRect, &error);
  529.                 FW_FailOnError(error);
  530.                 screenRect.Inset(FW_IntToFixed(3), FW_IntToFixed(3));    // leave space around window structure area
  531.             
  532.                 // ----- call the part to get a custom size (interior size) -----
  533.                 FW_CPoint proposedSize(screenRect.Width() - borderSize.left - borderSize.right, 
  534.                                        screenRect.Height() - borderSize.top - borderSize.bottom);
  535.                 this->AdjustZoomedWindowSize(ev, proposedSize);
  536.                 
  537.                 fWindow->PrivMacDoZoom(ev, proposedSize, borderSize, screenRect, message);
  538.             }
  539.             break;
  540.         
  541.         case inGrow:
  542.             PrivMacInGrowBox(ev, windowEvent);
  543.             break;
  544.  
  545.         case inGoAway:
  546.              if (fWindow->IsFloating(ev)) 
  547.                 fWindow->Hide(ev);
  548.             else
  549.                 handled = FW_kNotHandled;
  550.             break;
  551.             
  552.         default:
  553.             handled = FW_kNotHandled;
  554.     }
  555.     
  556.     return handled;
  557. }
  558. #endif
  559.  
  560. //----------------------------------------------------------------------------------------
  561. // FW_CFrame::AdjustZoomedWindowSize
  562. //----------------------------------------------------------------------------------------
  563. //    proposedSize is the interior size of the window
  564.  
  565. void FW_CFrame::AdjustZoomedWindowSize(Environment *ev, FW_CPoint& proposedSize)
  566. {
  567. FW_UNUSED(ev);
  568. FW_UNUSED(proposedSize);
  569. }
  570.  
  571. //----------------------------------------------------------------------------------------
  572. // FW_CFrame::AdjustWindowGrowLimits
  573. //----------------------------------------------------------------------------------------
  574. //    minSize and maxSize are the interior size of the window
  575.  
  576. void FW_CFrame::AdjustWindowGrowLimits(Environment* ev, FW_CPoint& minSize, FW_CPoint& maxSize)
  577. {
  578. FW_UNUSED(ev);
  579. FW_UNUSED(minSize);
  580. FW_UNUSED(maxSize);
  581. }
  582.  
  583. //----------------------------------------------------------------------------------------
  584. //    FW_CFrame::HandleAdjustMenus
  585. //----------------------------------------------------------------------------------------
  586.  
  587. FW_Handled FW_CFrame::HandleAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  588.                                         FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  589. {
  590.     if (hasMenuFocus)
  591.     {
  592.         // ----- Only if the target is the content view -----
  593.         if (GetTarget(ev) == fContentView)    
  594.         {
  595.             FW_CSelection* selection = fPresentation->GetSelection(ev);
  596.             FW_Boolean hasSelection = selection && !selection->IsEmpty(ev);
  597.         
  598.             // ----- Edit Menu -----
  599.             // If read only clear, cut past items will be disabled in FW_CPart::HandleAdjustMenus
  600.             menuBar->EnableCommand(ev, kODCommandClear, hasSelection && !GetPart(ev)->IsReadOnly(ev));
  601.             menuBar->EnableCommand(ev, kODCommandCut, hasSelection && !GetPart(ev)->IsReadOnly(ev));
  602.             menuBar->EnableCommand(ev, kODCommandCopy, hasSelection);
  603.             
  604.             if (!fInfoCommandAdjusted)    // may have been done by FW_CEmbeddingFrame::HandleAdjustMenus
  605.             {
  606.                 FW_CString infoString;
  607.                 FW_Boolean gotInfo = PrivGetInfoString(ev, selection, infoString);
  608.  
  609.                 if (!gotInfo || infoString.IsEmpty())
  610.                 {
  611.                     // Load default command string: "Part Info..."
  612.                     ::FW_PrivLoadODFString(ev, FW_kPartInfoString, infoString);
  613.                 }
  614.  
  615.                 //--- Set up the Info item ---
  616.                 menuBar->SetItemString(ev, kODCommandGetPartInfo, infoString);
  617.                 menuBar->EnableCommand(ev, kODCommandGetPartInfo, gotInfo);
  618.             }
  619.         }
  620.         
  621.         menuBar->EnableCommand(ev, kODCommandViewAsWin, !IsTopFrame(ev));
  622.     }
  623.     
  624.     fInfoCommandAdjusted = false;    // reset for next time
  625.  
  626.     return FW_CSuperView::HandleAdjustMenus(ev, menuBar, hasMenuFocus, isRoot);
  627. }
  628.  
  629. //----------------------------------------------------------------------------------------
  630. //    FW_CFrame::IsTopFrame
  631. //----------------------------------------------------------------------------------------
  632. //    IsTopFrame returns true if this frame is a sub-frame of the root frame
  633.  
  634. FW_Boolean FW_CFrame::IsTopFrame(Environment* ev) const
  635. {
  636.     if (IsRoot(ev))
  637.         return TRUE;
  638.     
  639.     FW_CAcquiredODFrame aqContainingFrame = AcquireContainingFrame(ev);
  640.     return IsSubframe(ev) && aqContainingFrame->IsRoot(ev);
  641. }
  642.  
  643. //----------------------------------------------------------------------------------------
  644. //    FW_CFrame::IsSiblingFrameOf
  645. //----------------------------------------------------------------------------------------
  646. //    Look if both frames are from the same part and have the same presentation. Returns FALSE
  647. //    if otherODFrame is NULL.
  648.  
  649. FW_Boolean FW_CFrame::IsSiblingFrameOf(Environment *ev, ODFrame* otherODFrame) const
  650. {
  651.     if (otherODFrame == NULL)
  652.         return FALSE;
  653.         
  654.     FW_CAcquiredODPart otherPart = otherODFrame->AcquirePart(ev);
  655.     if (GetODPart(ev) == otherPart)
  656.     {
  657.         FW_CFrame* otherFrame = FW_CFrame::ODtoFWFrame(ev, otherODFrame);
  658.         return GetPresentation(ev) == otherFrame->GetPresentation(ev);
  659.     }
  660.     
  661.     return FALSE;
  662. }
  663.  
  664. //----------------------------------------------------------------------------------------
  665. //    FW_CFrame::HasSamePartEditorAs
  666. //----------------------------------------------------------------------------------------
  667. //    Look if the presentation of the otherFrame is the same as mine. Returns TRUE even if they
  668. //    have two different instances of the editor.
  669.  
  670. FW_Boolean FW_CFrame::HasSamePartEditorAs(Environment *ev, ODFrame* otherFrame) const
  671. {
  672.     if (otherFrame != NULL)
  673.     {
  674.         ODTypeToken proposedToken = otherFrame->GetPresentation(ev);
  675.         FW_CPartPresentationIterator ite(fPart);
  676.         for (FW_CPresentation* presentation = ite.First();
  677.             ite.IsNotComplete();
  678.             presentation = ite.Next())
  679.         {
  680.             if (presentation->GetPresentationType(ev) == proposedToken)
  681.                 return TRUE;
  682.         }
  683.     }
  684.     
  685.     return FALSE;
  686. }
  687.  
  688. //----------------------------------------------------------------------------------------
  689. //    FW_CFrame::HasSameDraftAs
  690. //----------------------------------------------------------------------------------------
  691.  
  692. FW_Boolean FW_CFrame::HasSameDraftAs(Environment* ev, ODFrame* otherODFrame) const
  693. {
  694.     FW_Boolean result = false;
  695.     
  696.     if (otherODFrame)
  697.     {
  698.         ODStorageUnit* su = otherODFrame->GetStorageUnit(ev);
  699.         if (su)
  700.             result = (GetPart(ev)->GetDraft(ev) == su->GetDraft(ev));
  701.     }
  702.     
  703.     return result;
  704. }
  705.  
  706. //----------------------------------------------------------------------------------------
  707. //    FW_CFrame::FocusStateChanged
  708. //----------------------------------------------------------------------------------------
  709. //    When overridden, call inherited::FocusStateChanged FIRST
  710.  
  711. void FW_CFrame::FocusStateChanged(Environment *ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
  712. {
  713.     if (focus == FW_CPart::fgSelectionFocusToken)
  714.     {
  715.         fPart->PrivSetLastActiveFrame(this);
  716.  
  717.         if (newState)
  718.         {
  719.             fHasSelectionFocus = TRUE;
  720.             GetTarget(ev)->ActivateTarget(ev, false);
  721.             
  722.             // Handle case of multiple parts sharing the same floating windows
  723.             FW_CFloatingWindow::TransferOwnership(ev, fPart->GetODPart(ev));
  724.             
  725.             // Show the floating windows except if frame has modal focus (i.e. Dialogs)
  726.             if (!HasModalFocus(ev))
  727.                 FW_CFloatingWindow::HideShowFloatingWindows(ev, TRUE, fPart->GetODPart(ev));
  728. //                fShowPaletteOnMouseUp = TRUE;
  729.         }
  730.         else
  731.         {
  732.             //     Close the selection if I become deactive and the newOwner is not NULL and
  733.             //    not one of the part frame and there is not drag pending
  734.             FW_CSelection* selection = fPresentation->GetSelection(ev);
  735.             FW_Boolean samePart = FALSE;
  736.             if (newOwner != NULL)
  737.             {
  738.                 FW_CAcquiredODPart otherPart = newOwner->AcquirePart(ev);
  739.                 samePart = (otherPart == fPart->GetODPart(ev));
  740.             }
  741.              if (selection && !samePart && !fPresentation->PrivIsDragPending())        
  742.                 selection->CloseSelection(ev);
  743.  
  744.             fHasSelectionFocus = FALSE;
  745.             GetTarget(ev)->DeactivateTarget(ev);
  746.             
  747.             if (!HasSamePartEditorAs(ev, newOwner) || !HasSameDraftAs(ev, newOwner))
  748.                 FW_CFloatingWindow::HideShowFloatingWindows(ev, FALSE);
  749.         }
  750.     }
  751.     else if (focus == FW_CPart::fgMenuFocusToken)
  752.     {
  753.         if (newState)
  754.             InstallMenus(ev);
  755.     }
  756.     else if (focus == FW_CPart::fgScrollingFocusToken)
  757.     {
  758.         fHasScrollingFocus = newState;
  759.     }
  760. }
  761.  
  762. //----------------------------------------------------------------------------------------
  763. //    FW_CFrame::CanBeActiveFrame
  764. //----------------------------------------------------------------------------------------
  765.  
  766. FW_Boolean FW_CFrame::CanBeActiveFrame(Environment* ev) const
  767. {
  768.     FW_ASSERT(GetWindow(ev) != NULL);
  769.     return fCanBeActiveFrame && !GetWindow(ev)->IsFloating(ev) && !IsFrozen(ev) && (GetViewType(ev) == FW_CPart::fgViewAsFrameToken);
  770. }
  771.  
  772. //----------------------------------------------------------------------------------------
  773. //    FW_CFrame::ODtoFWFrame
  774. //----------------------------------------------------------------------------------------
  775.  
  776. FW_CFrame* FW_CFrame::ODtoFWFrame(Environment *ev, ODFrame* odFrame)
  777. {
  778.     // In certain cases we get passed a bogus ODFrame. Do a (skanky) sanity check
  779.     // to make sure this frame is really ours.
  780.     
  781.     FW_CFrame* frame = kODNULL;
  782.     
  783.     if (odFrame) {
  784.         FW_CFrame* frame = (FW_CFrame*)odFrame->GetPartInfo(ev);
  785.         if (frame) {
  786.             // If odFrame is not ours, frame points to a random spot of memory.
  787.             // Hopefully the fODFrame offset in that memory won't have 4 bytes 
  788.             // which are this odFrame*.
  789.             if (frame->GetODFrame(ev) == odFrame)
  790.                 return frame;
  791.         }
  792.     }
  793.     
  794.     return kODNULL;
  795. }
  796.  
  797. //----------------------------------------------------------------------------------------
  798. //     FW_CFrame::FrameShapeChanged
  799. //----------------------------------------------------------------------------------------
  800. //    When overridden, call inherited::FrameShapeChanged first
  801.  
  802. void FW_CFrame::FrameShapeChanged(Environment* ev)
  803. {
  804.     FW_CRect frameRect;
  805.     PrivGetFrameShapeBounds(ev, frameRect);
  806.     FW_CPoint newSize = frameRect.Size();
  807.     
  808.     if (GetViewType(ev) == FW_CPart::fgViewAsFrameToken)
  809.     {
  810. #ifdef FW_BUILD_WIN
  811.         MoveSizeShadowWindow(ev);
  812. #endif
  813.         // Change the size and refresh modified region.  (This will in turn call SetExtent 
  814.         // and adjust the layout of subviews if the frame is not the content view)
  815.         SetSize(ev, newSize, FW_kInvalidate);
  816.     }
  817.     else
  818.     {
  819.         // Use the FW_CView method to avoid resizing the frame's subviews
  820.         // when it's not displayed as a frame
  821.         FW_CView::SetSize(ev, newSize, FW_kInvalidate);
  822.     }
  823.     
  824.     UpdateUsedAndActiveShapes(ev);
  825. }
  826.  
  827. //----------------------------------------------------------------------------------------
  828. //    FW_CFrame::SetActiveFacet
  829. //----------------------------------------------------------------------------------------
  830.  
  831. void FW_CFrame::SetActiveFacet(Environment* ev, ODFacet*  activeFacet)
  832. {
  833. FW_UNUSED(ev);
  834.     fActiveFacet = activeFacet;
  835. }
  836.  
  837. //----------------------------------------------------------------------------------------
  838. //    FW_CFrame::UpdateUsedAndActiveShapes
  839. //----------------------------------------------------------------------------------------
  840.  
  841. void FW_CFrame::UpdateUsedAndActiveShapes(Environment* ev)
  842. {
  843.     // ----- Used Shape -----
  844.     UpdateUsedShape(ev);
  845.  
  846.     // ----- Update Active Shape for every facets -----
  847.     FW_CFrameFacetIterator iter(ev, this);
  848.     for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
  849.     {
  850.         UpdateActiveShape(ev, facet);
  851.     }
  852. }
  853.  
  854. //----------------------------------------------------------------------------------------
  855. //    FW_CFrame::UpdateUsedShape
  856. //----------------------------------------------------------------------------------------
  857.  
  858. void FW_CFrame::UpdateUsedShape(Environment* ev)
  859. {
  860.     // ----- Used Shape -----
  861.     FW_CAcquiredODShape aqUsedShape;
  862.     
  863.     PrivCreateViewAs(ev);
  864.     if (fViewAs == NULL)
  865.     {
  866.         //    ----- By default the used shape is the frame shape
  867.         FW_CAcquiredODShape aqFrameShape = FW_CopyAndRelease(ev, AcquireFrameShape(ev, NULL));
  868.         aqUsedShape = AdjustUsedShape(ev, aqFrameShape);
  869.     }
  870.     else
  871.     {
  872.         aqUsedShape = FW_CopyAndRelease(ev, fViewAs->AcquireUsedShape(ev));        
  873.     }
  874.     
  875.     // ----- if aqUsedShape is NULL OpenDoc will use the frame shape
  876.     ChangeUsedShape(ev, aqUsedShape, NULL);        
  877. }
  878.  
  879. //----------------------------------------------------------------------------------------
  880. //    FW_CFrame::UpdateActiveShape
  881. //----------------------------------------------------------------------------------------
  882.  
  883. void FW_CFrame::UpdateActiveShape(Environment* ev, ODFacet* facet)
  884. {
  885.     FW_CAcquiredODShape aqActiveShape;
  886.     
  887.     // ---- the Active shape is a copy of the Used shape by default
  888.     FW_CAcquiredODShape aqProposedActiveShape = FW_CopyAndRelease(ev, AcquireUsedShape(ev));
  889.     
  890.     PrivCreateViewAs(ev);
  891.     if (fViewAs == NULL) 
  892.         aqActiveShape = AdjustActiveShape(ev, facet, aqProposedActiveShape);
  893.     else
  894.         aqActiveShape = aqProposedActiveShape;
  895.         
  896.     facet->ChangeActiveShape(ev, aqActiveShape, NULL);    
  897. }
  898.  
  899. //----------------------------------------------------------------------------------------
  900. //    FW_CFrame::AdjustUsedShape
  901. //----------------------------------------------------------------------------------------
  902. //    suggestedUsedShape is the frame shape. The default implementation returns NULL because
  903. //    we don't want to maintain our own used shape.
  904.  
  905. ODShape* FW_CFrame::AdjustUsedShape(Environment* ev, ODShape* suggestedUsedShape)
  906. {
  907. FW_UNUSED(ev);
  908. FW_UNUSED(suggestedUsedShape);
  909.     return NULL;
  910. }
  911.  
  912. //----------------------------------------------------------------------------------------
  913. //    FW_CFrame::AdjustActiveShape
  914. //----------------------------------------------------------------------------------------
  915. //    suggestedActiveShape is the used shape. The default implementation returns NULL because
  916. //    we don't want to maintain an active shape
  917.  
  918. ODShape* FW_CFrame::AdjustActiveShape(Environment* ev, ODFacet* facet, ODShape* suggestedActiveShape)
  919. {
  920. FW_UNUSED(ev);
  921. FW_UNUSED(facet);
  922. FW_UNUSED(suggestedActiveShape);
  923.     return NULL;
  924. }
  925.  
  926. //----------------------------------------------------------------------------------------
  927. //    FW_CFrame::RequestFrameShape
  928. //----------------------------------------------------------------------------------------
  929.  
  930. FW_Boolean FW_CFrame::RequestFrameShape(Environment *ev, ODShape* shape, ODCanvas* biasCanvas)
  931. {
  932.     FW_CAcquiredODShape aqOldFrameShape = FW_CopyAndRelease(ev, AcquireFrameShape(ev, biasCanvas));
  933.     
  934.     FW_CAcquiredODShape aqNewFrameShape = fODFrame->RequestFrameShape(ev, shape, biasCanvas);
  935.     
  936.     FW_Boolean changed = !aqNewFrameShape->IsSameAs(ev, aqOldFrameShape);
  937.     
  938.     if (changed)
  939.         FrameShapeChanged(ev); 
  940.     
  941.     return changed;
  942. }
  943.  
  944. //----------------------------------------------------------------------------------------
  945. //     FW_CFrame::FacetAdded
  946. //----------------------------------------------------------------------------------------
  947. //    When overridden call inherited::FacetAdded FIRST
  948.  
  949. void FW_CFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  950. {        
  951.     // ----- Install the newest facet as the active facet of this frame
  952.     this->SetActiveFacet(ev, facet);
  953.     
  954.     // ----- Create the window wrapper -----
  955.     // ----- We have to wait for facet added because 
  956.     // ----- at FrameAdded it is too early
  957.     FW_CAcquiredODWindow aqODWindow = fODFrame->AcquireWindow(ev);
  958.     this->PrivCreateWindow(ev, aqODWindow);    // Might not create a FW_CWindow if already has one    
  959.  
  960.     // ----- for floating windows: remove all the foci by setting an empty set.
  961.     if (aqODWindow->IsFloating(ev))
  962.     {
  963.         GetPresentation(ev)->AdoptFocusSet(ev, NULL);
  964.     }
  965.     
  966.     // ----- Create the Shadow Window for Windows
  967. #ifdef FW_BUILD_WIN
  968.     CreateShadowWindow(ev);
  969. #endif    
  970.  
  971.     // ----- First facet: update used shape and create the sub-views
  972.     if (facetCount == 1)
  973.     {
  974.         UpdateUsedShape(ev);
  975.         
  976.         // Create views only once during the frame's life!
  977.         if (!fSubViewsCreated)
  978.             PrivInstantiateViews(ev);
  979.         
  980.         if (fInternalTransformRealigmentNeeded)
  981.             PrivRealignInternalTransform(ev);
  982.             
  983.         if (fAdoptsContainerProperties)
  984.             SynchContainingPartProperties(ev);
  985.     }
  986.  
  987.     // ----- Give my frame a chance to update the active shape of the facet -----
  988.     UpdateActiveShape(ev, facet);
  989.     
  990.     // ----- Finally invalidate the content of the facet so it will be redrawn -----
  991.     FW_CAcquiredODShape aqUsedShape = AcquireUsedShape(ev); 
  992.     facet->Invalidate(ev, aqUsedShape, NULL);
  993. }
  994.  
  995. //----------------------------------------------------------------------------------------
  996. //     FW_CFrame::FacetRemoved
  997. //----------------------------------------------------------------------------------------
  998. //    When overridden call inherited::FacetRemoved last
  999.  
  1000. void FW_CFrame::FacetRemoved(Environment* ev, ODFacet* odFacet, unsigned short facetCount)
  1001. {
  1002.     if (this->GetActiveFacet(ev) == odFacet)
  1003.     {
  1004.         FW_CFrameFacetIterator iter(ev, this);
  1005.         this->SetActiveFacet(ev, iter.First(ev));
  1006.     }
  1007.     
  1008.     // ----- Delete the fWindow if it was the last facet -----
  1009.     if (facetCount == 1)
  1010.     {
  1011.         FW_ASSERT(fWindow);
  1012.         
  1013.         DeleteAndResetViews(ev);
  1014.         
  1015.         if (!fWindow->IsFloating(ev))    // If floating window the part has to release
  1016.             delete fWindow;
  1017.         
  1018.         fWindow = NULL;
  1019.     }
  1020. }
  1021.  
  1022. //----------------------------------------------------------------------------------------
  1023. //    FW_CFrame::GetWindow
  1024. //----------------------------------------------------------------------------------------
  1025.  
  1026. FW_CWindow* FW_CFrame::GetWindow(Environment* ev) const
  1027. {
  1028. FW_UNUSED(ev);
  1029.     return fWindow;
  1030. }
  1031.  
  1032. //----------------------------------------------------------------------------------------
  1033. //    FW_CFrame::ViewTypeChanged
  1034. //----------------------------------------------------------------------------------------
  1035.  
  1036. void FW_CFrame::ViewTypeChanged(Environment* ev, 
  1037.                                 ODTypeToken newViewType, 
  1038.                                 ODTypeToken oldViewType)
  1039. {
  1040. FW_UNUSED(oldViewType);
  1041.     Invalidate(ev);
  1042.     
  1043.     if (fViewAs != NULL)
  1044.         fPresentation->PrivReleaseViewAs(fViewAs);
  1045.     fViewAs = NULL;
  1046.     
  1047.     PrivCreateViewAs(ev);
  1048.         
  1049.     UpdateUsedAndActiveShapes(ev);
  1050.     
  1051.     Invalidate(ev);
  1052.     
  1053.     // ----- Only If I have an associated FW_MDroppableFrame -----
  1054.     if (fDroppable)
  1055.         fODFrame->SetDroppable(ev, FW_MDroppableFrame::PrivDroppableStateToBoolean(fDroppableState, newViewType));
  1056. }
  1057.  
  1058. //----------------------------------------------------------------------------------------
  1059. //    FW_CFrame::BuildThumbnail
  1060. //----------------------------------------------------------------------------------------
  1061. //    By default does nothing
  1062.  
  1063. void FW_CFrame::BuildThumbnail(Environment* ev, FW_CGraphicContext& gc, FW_CRect& usedRect)
  1064. {
  1065. FW_UNUSED(ev);
  1066. FW_UNUSED(gc);
  1067. FW_UNUSED(usedRect);
  1068. }
  1069.  
  1070. //----------------------------------------------------------------------------------------
  1071. //    FW_CFrame::GetIcon
  1072. //----------------------------------------------------------------------------------------
  1073. //    By default returns the part icon
  1074.  
  1075. FW_CIcon FW_CFrame::GetIcon(Environment* ev, short iconSize) const
  1076. {
  1077.     FW_PSharedLibraryResourceFile resourceFile(ev, fPart->GetPartInstance(ev));
  1078.     FW_CIcon icon(resourceFile, fPart->GetViewAsIconID(ev), iconSize);
  1079.     
  1080.     return icon;
  1081. }
  1082.  
  1083. //----------------------------------------------------------------------------------------
  1084. //    FW_CFrame::NewViewAs
  1085. //----------------------------------------------------------------------------------------
  1086.  
  1087. FW_CViewAs* FW_CFrame::NewViewAs(Environment* ev, ODTypeToken viewAsToken)
  1088. {
  1089.     return new FW_CViewAs(ev, viewAsToken);
  1090. }
  1091.  
  1092. //----------------------------------------------------------------------------------------
  1093. //    FW_CFrame::ChangePresentation
  1094. //----------------------------------------------------------------------------------------
  1095.  
  1096. void FW_CFrame::ChangePresentation(Environment* ev, FW_CPresentation* presentation)
  1097. {
  1098.     FW_ASSERT(presentation);
  1099.     if (presentation != fPresentation)
  1100.         fODFrame->ChangePresentation(ev, presentation->GetPresentationType(ev));
  1101. }
  1102.  
  1103. //----------------------------------------------------------------------------------------
  1104. //    FW_CFrame::PresentationChanged
  1105. //----------------------------------------------------------------------------------------
  1106.  
  1107. void FW_CFrame::PresentationChanged(Environment* ev)
  1108. {
  1109.     FW_ASSERT(fPresentation != NULL);
  1110.     
  1111.     FW_CPresentation* newPresentation = GetPart(ev)->PrivGetPresentation(ev, GetODFrame(ev));
  1112.     if (newPresentation == NULL)
  1113.         return;
  1114.     
  1115.     if (fViewAs)
  1116.     {
  1117.         fPresentation->PrivReleaseViewAs(fViewAs);
  1118.         fViewAs = NULL;
  1119.     }
  1120.  
  1121.     fPresentation->PrivRemoveFrame(ev, this);
  1122.     newPresentation->PrivAddFrame(ev, this);
  1123.     
  1124.     fPresentation = newPresentation;
  1125.     
  1126.     if (fSubViewsCreated)
  1127.     {
  1128.         DeleteAndResetViews(ev);
  1129.         PrivInstantiateViews(ev);
  1130.         Invalidate(ev);
  1131.     }
  1132. }
  1133.  
  1134. //----------------------------------------------------------------------------------------
  1135. //    FW_CFrame::SequenceChanged
  1136. //----------------------------------------------------------------------------------------
  1137.  
  1138. void FW_CFrame::SequenceChanged(Environment* ev)
  1139. {    
  1140. FW_UNUSED(ev);
  1141. }
  1142.  
  1143. //----------------------------------------------------------------------------------------
  1144. //    FW_CFrame::HandleActivateEvent
  1145. //----------------------------------------------------------------------------------------
  1146.  
  1147. void FW_CFrame::HandleActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
  1148. {
  1149.     if (theActivateEvent.IsActivating(ev))
  1150.     {
  1151.         if (fNeedsFoci)
  1152.             ActivateFrame(ev, theActivateEvent.GetFacet(ev));
  1153.         
  1154.         // ----- Try scrolling focus -----
  1155.         if (fNeedsScrollingFocus)
  1156.             PrivRequestScrollingFocus(ev);
  1157.     }
  1158.     else
  1159.     {
  1160.         fNeedsFoci = fHasSelectionFocus;
  1161.         fNeedsScrollingFocus = fHasScrollingFocus;
  1162.     }
  1163.     
  1164.     FW_CSuperView::HandleActivateEvent(ev, theActivateEvent);
  1165. }
  1166.  
  1167. //----------------------------------------------------------------------------------------
  1168. //    FW_CFrame::SubViewWasRemoved
  1169. //----------------------------------------------------------------------------------------
  1170.  
  1171. void FW_CFrame::SubViewWasRemoved(Environment* ev, FW_CView* subView)
  1172. {
  1173.     // if the view being removed was the content view, set the content view to
  1174.     // the frame
  1175.     if (subView == GetContentView(ev))
  1176.         SetContentView(ev, NULL);
  1177.     
  1178.     if (subView == fViewUnderCursor)
  1179.         fViewUnderCursor = NULL;
  1180. }
  1181.  
  1182. //----------------------------------------------------------------------------------------
  1183. //    FW_CFrame::GetFrame
  1184. //----------------------------------------------------------------------------------------
  1185.  
  1186. FW_CFrame* FW_CFrame::GetFrame(Environment* ev) const
  1187. {
  1188. FW_UNUSED(ev);
  1189.     return (FW_CFrame*)this; // cast away const
  1190. }
  1191.  
  1192. //----------------------------------------------------------------------------------------
  1193. //    FW_CFrame::IsFrame
  1194. //----------------------------------------------------------------------------------------
  1195.  
  1196. FW_Boolean FW_CFrame::IsFrame(Environment* ev) const
  1197. {
  1198. FW_UNUSED(ev);
  1199.     return true;
  1200. }
  1201.  
  1202. //----------------------------------------------------------------------------------------
  1203. //    FW_CFrame::HandleSuspendResumeEvent
  1204. //----------------------------------------------------------------------------------------
  1205.  
  1206. FW_Handled FW_CFrame::HandleSuspendResumeEvent(Environment* ev, const FW_CSuspendResumeEvent& theResumeSuspendEvent)
  1207. {
  1208.     FW_Boolean backToForeground = !theResumeSuspendEvent.IsGoingToBackground(ev);
  1209.     
  1210.     // [LSD] see later to use keyFocus and menuFocus instead for target management
  1211.     if (HasSelectionFocus(ev))
  1212.     {
  1213.         if (backToForeground)
  1214.             GetTarget(ev)->ActivateTarget(ev, false);
  1215.         else
  1216.             GetTarget(ev)->DeactivateTarget(ev);
  1217.     }
  1218.  
  1219.     if (GetWindow(ev)->IsFloating(ev) && IsRoot(ev))
  1220.     {
  1221.         // ----- We have to test that this frame belongs to the part with the selection focus
  1222.         ODArbitrator* arbitrator =  FW_CSession::GetArbitrator(ev);
  1223.         FW_CAcquiredODFrame aqODFrame = arbitrator->AcquireFocusOwner(ev, FW_CPart::fgSelectionFocusToken);
  1224.         if (aqODFrame != NULL)
  1225.         {
  1226.             FW_CAcquiredODPart aqODPart = aqODFrame->AcquirePart(ev);
  1227.             if (aqODPart == fPart->GetODPart(ev))
  1228.                 FW_CFloatingWindow::HideShowFloatingWindows(ev, backToForeground, aqODPart);
  1229.         }
  1230.     }
  1231.     
  1232.     return FW_kNotHandled;
  1233. }
  1234.  
  1235. //----------------------------------------------------------------------------------------
  1236. //    FW_CFrame::HandleMouseEnter
  1237. //----------------------------------------------------------------------------------------
  1238. // where is in frame coordinate
  1239.  
  1240. FW_Handled FW_CFrame::HandleMouseEnter(Environment *ev, ODFacet* odFacet, const FW_CPoint& where, ODEventInfo* eventInfo)
  1241. {
  1242.     fViewUnderCursor = GetViewContaining(ev, odFacet, where);
  1243.     if (fViewUnderCursor == NULL)
  1244.         return FW_kNotHandled;
  1245.  
  1246.     if (!fViewUnderCursor->AdjustCursor(ev, odFacet, where, eventInfo))
  1247.         FW_gArrowCursor.Select();
  1248.  
  1249.     return (fViewUnderCursor->IsEnabled(ev)) ? 
  1250.         fViewUnderCursor->DoMouseEnter(ev, odFacet, where, eventInfo) : FW_kNotHandled;
  1251. }
  1252.  
  1253. //----------------------------------------------------------------------------------------
  1254. //    FW_CFrame::HandleMouseLeave
  1255. //----------------------------------------------------------------------------------------
  1256.  
  1257. FW_Handled FW_CFrame::HandleMouseLeave(Environment *ev, ODFacet* odFacet, ODEventInfo* eventInfo)
  1258. {
  1259.     FW_gArrowCursor.Select();
  1260.     
  1261.     FW_Handled result = fViewUnderCursor ? fViewUnderCursor->DoMouseLeave(ev, odFacet, eventInfo) : FW_kNotHandled;
  1262.  
  1263.     fViewUnderCursor = NULL;
  1264.     
  1265.     return result;
  1266. }
  1267.  
  1268. //----------------------------------------------------------------------------------------
  1269. //    FW_CFrame::HandleMouseWithin
  1270. //----------------------------------------------------------------------------------------
  1271. // where is in frame coordinate
  1272.  
  1273. FW_Handled FW_CFrame::HandleMouseWithin(Environment *ev, ODFacet* odFacet, const FW_CPoint& theMousePoint, ODEventInfo* eventInfo)
  1274. {
  1275.     FW_CView* viewUnderCursor = GetViewContaining(ev, odFacet, theMousePoint);
  1276.     if (viewUnderCursor == NULL)
  1277.         return FW_kNotHandled;
  1278.         
  1279.     if (viewUnderCursor != fViewUnderCursor)
  1280.     {
  1281.         if (fViewUnderCursor != NULL)
  1282.             fViewUnderCursor->DoMouseLeave(ev, odFacet, eventInfo);
  1283.         
  1284.         viewUnderCursor->DoMouseEnter(ev, odFacet, theMousePoint, eventInfo);
  1285.     }
  1286.     else
  1287.         viewUnderCursor->DoMouseWithin(ev, odFacet, theMousePoint, eventInfo);
  1288.         
  1289.     fViewUnderCursor = viewUnderCursor;
  1290.     
  1291.     if (!fViewUnderCursor->AdjustCursor(ev, odFacet, theMousePoint, eventInfo))
  1292.         FW_gArrowCursor.Select();
  1293.         
  1294.     return FW_kHandled;
  1295. }
  1296.  
  1297. //----------------------------------------------------------------------------------------
  1298. //    FW_CFrame::GeometryChanged
  1299. //----------------------------------------------------------------------------------------
  1300. //    the geometry (clip shape or external transform) of one of my facet or one of my
  1301. //    embedding facet as changed
  1302.  
  1303. void FW_CFrame::GeometryChanged(Environment *ev,
  1304.                                 ODFacet* odFacet,
  1305.                                 FW_Boolean clipShapeChanged,
  1306.                                 FW_Boolean transformChanged)
  1307. {
  1308. FW_UNUSED(ev);
  1309. FW_UNUSED(odFacet);
  1310. FW_UNUSED(clipShapeChanged);
  1311. FW_UNUSED(transformChanged);
  1312.  
  1313. #ifdef FW_BUILD_WIN
  1314.     MoveSizeShadowWindow(ev);
  1315. #endif
  1316. }
  1317.  
  1318. //----------------------------------------------------------------------------------------
  1319. //    FW_CFrame::HandleDraw
  1320. //----------------------------------------------------------------------------------------
  1321. // invalidShape is in frame coordinate
  1322.  
  1323. FW_Handled FW_CFrame::HandleDraw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  1324. {
  1325.     //     if the facet doesn't have a graphicdevice it is not one of my facet anymore
  1326.     //    That means that FacetRemoved has been called but my container is still trying
  1327.     //    do draw me.[HLX] Might be a bug in OpenDoc. Might have been fixed in DR4
  1328.     if (FW_GetFacetGraphicDevice(ev, odFacet) == NULL)
  1329.         return FW_kHandled;
  1330.  
  1331. #ifdef FW_BUILD_MAC
  1332.     // [HLX] there is a bug in OpenDoc. Sometime the invalidShape is one pixel too small
  1333.     invalidShape->Outset(ev, 0x00010000);
  1334. #endif
  1335.  
  1336. #ifdef FW_BUILD_WIN
  1337.     // [HLX] bug in windows? the invalidShape is in pixels instead of points
  1338.     invalidShape->Outset(ev, 0x00010000);    // [HLX] Because of rounding errors
  1339.     FW_CGraphicDevice *device = FW_GetFacetGraphicDevice(ev, odFacet);
  1340.     device->PixelToPoint(ev, aqInvalidShape);
  1341. #endif
  1342.     
  1343.     // ----- Check if the fViewAs has been created
  1344.     PrivCreateViewAs(ev);
  1345.     if (fViewAs == NULL)
  1346.     {
  1347.         FW_CSuperView::HandleDraw(ev, odFacet, invalidShape);
  1348.         
  1349.         // ----- If hilited state draw the hilite state
  1350.         if (odFacet->GetHighlight(ev) == kODFullHighlight)
  1351.             DrawFullHighlight(ev, odFacet, invalidShape);
  1352.     }
  1353.     else
  1354.     {
  1355.         fViewAs->Draw(ev, this, odFacet, invalidShape);
  1356.     }
  1357.  
  1358.     return FW_kHandled;
  1359. }
  1360.  
  1361. //----------------------------------------------------------------------------------------
  1362. //    FW_CFrame::Draw
  1363. //----------------------------------------------------------------------------------------
  1364. // invalidShape is in content coordinate
  1365.  
  1366. void FW_CFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  1367. {
  1368. FW_UNUSED(ev);
  1369. FW_UNUSED(odFacet);
  1370. FW_UNUSED(invalidShape);
  1371. }
  1372.  
  1373. //----------------------------------------------------------------------------------------
  1374. //    FW_CFrame::DrawFullHighlight
  1375. //----------------------------------------------------------------------------------------
  1376.  
  1377. void FW_CFrame::DrawFullHighlight(Environment *ev, ODFacet* facet, ODShape* invalidShape)
  1378. {
  1379.     FW_CFrameContext fc(ev, facet, invalidShape);
  1380.     FW_CAcquiredODShape usedShape = AcquireUsedShape(ev);
  1381.     FW_CRegionShape::RenderRegion(fc, usedShape, FW_kFill, FW_CInk(FW_kSystemHilite));
  1382. }
  1383.  
  1384. //----------------------------------------------------------------------------------------
  1385. //    FW_CFrame::HighlightChanged
  1386. //----------------------------------------------------------------------------------------
  1387.  
  1388. void FW_CFrame::HighlightChanged(Environment *ev, ODFacet* facet, ODHighlight from, ODHighlight to)
  1389. {
  1390.     // In the Icon/Thumbnail case just invalidate the facet
  1391.     if (GetViewType(ev) != FW_CPart::fgViewAsFrameToken)
  1392.         facet->Invalidate(ev, NULL, NULL);    // NULL for the shape is fine
  1393.     else
  1394.     {        
  1395.         if ((from == kODNoHighlight || from == kODDimHighlight) && (to == kODFullHighlight))
  1396.             DrawFullHighlight(ev, facet , NULL);
  1397.         else if ((to == kODNoHighlight || to == kODDimHighlight) && (from == kODFullHighlight)) 
  1398.             DrawFullHighlight(ev, facet, NULL);
  1399.     }
  1400. }
  1401.  
  1402. //----------------------------------------------------------------------------------------
  1403. //    FW_CFrame::AdjustCursor
  1404. //----------------------------------------------------------------------------------------
  1405. // where is in frame coordinate
  1406.  
  1407. FW_Handled FW_CFrame::AdjustCursor(Environment *ev, ODFacet* odFacet, const FW_CPoint& theMousePoint, ODEventInfo* eventInfo)
  1408. {
  1409. FW_UNUSED(ev);
  1410. FW_UNUSED(odFacet);
  1411. FW_UNUSED(theMousePoint);
  1412. FW_UNUSED(eventInfo);
  1413.  
  1414.     return FW_kNotHandled;
  1415. }
  1416.  
  1417. //----------------------------------------------------------------------------------------
  1418. //    FW_CFrame::GetODPart
  1419. //----------------------------------------------------------------------------------------
  1420.  
  1421. ODPart* FW_CFrame::GetODPart(Environment* ev) const
  1422. {
  1423.     return fPart->GetODPart(ev);
  1424. }
  1425.  
  1426. //----------------------------------------------------------------------------------------
  1427. //    FW_CFrame::SetContentView
  1428. //----------------------------------------------------------------------------------------
  1429.  
  1430. void FW_CFrame::SetContentView(Environment* ev, FW_CSuperView* view) 
  1431. {
  1432.     if (fContentView != view)
  1433.     {
  1434.         fContentView = view;
  1435.  
  1436.         // Make the content view the default target for menu and keyboard events
  1437.         fTarget = GetContentView(ev); // return this if fContentView is null
  1438.  
  1439.         // ----- if view == NULL I don't try to change the internal transform
  1440.         // ----- The frame might be closing down, in this case trying to acquire or change
  1441.         // ----- the internal transform is a bad idea
  1442.         if (view != NULL)
  1443.         {
  1444.             FW_CPoint contentViewTopLeft = FW_kZeroPoint;
  1445.         
  1446.             if (view != this)
  1447.             {
  1448.                 FW_CRect bounds = view->GetBounds(ev);
  1449.                 FW_CSuperView* superView = view->GetSuperView(ev);
  1450.                 if (superView)
  1451.                     superView->ViewContentToFrame(ev, bounds);
  1452.                 contentViewTopLeft = bounds.TopLeft();
  1453.             }
  1454.         
  1455.             PrivContentViewLocationChanged(ev, contentViewTopLeft);
  1456.         }
  1457.     }
  1458. }
  1459.  
  1460. //----------------------------------------------------------------------------------------
  1461. //    FW_CFrame::DeleteAndResetViews
  1462. //----------------------------------------------------------------------------------------
  1463.  
  1464. void FW_CFrame::DeleteAndResetViews(Environment* ev) 
  1465. {
  1466.     // This method allows to reset everything before reloading fresh views (for instance
  1467.     // after modifying them with a view editor)
  1468.  
  1469.     DeleteSubViews(ev);
  1470.     
  1471.     delete fScroller;
  1472.     fScroller = NULL;
  1473.  
  1474.     fContentView = NULL;
  1475.     fViewUnderCursor = NULL;
  1476.     
  1477.     SetTarget(ev, this);
  1478.     
  1479.     fSubViewsCreated = false;
  1480. }
  1481.  
  1482. //----------------------------------------------------------------------------------------
  1483. //    FW_CFrame::AdoptScroller
  1484. //----------------------------------------------------------------------------------------
  1485.  
  1486. void FW_CFrame::AdoptScroller(Environment* ev, FW_CScroller* scroller)
  1487. {
  1488.     // [LSD] Set the content view's scrolling flag in case it wasn't set in ctor
  1489.     //         To be reviewed.
  1490.     FW_CSuperView* contentView = GetContentView(ev);  // could be the frame itself
  1491.     if (contentView->IsScrolling(ev) == false)
  1492.     {
  1493.         contentView->SetScrollingInX(ev, true);
  1494.         contentView->SetScrollingInY(ev, true);
  1495.     }
  1496.     
  1497. #ifdef FW_DEBUG
  1498.     scroller->PrivCheckFrame(ev);
  1499. #endif        
  1500.     
  1501.     // [LSD] don't allow to change an existing scroller for now
  1502.     FW_ASSERT(fScroller == NULL);
  1503.     fScroller = scroller;
  1504.     
  1505.     if (fScroller)
  1506.         fScroller->PrivRealignScroller(ev);
  1507. }
  1508.  
  1509. //----------------------------------------------------------------------------------------
  1510. //    FW_CFrame::ExternalizeFrame
  1511. //----------------------------------------------------------------------------------------
  1512.  
  1513. void FW_CFrame::ExternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  1514. {
  1515. FW_UNUSED(ev);
  1516. FW_UNUSED(storageUnitView);
  1517.     // For subclasses
  1518. }
  1519.  
  1520. //----------------------------------------------------------------------------------------
  1521. //    FW_CFrame::InternalizeFrame
  1522. //----------------------------------------------------------------------------------------
  1523.  
  1524. void FW_CFrame::InternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  1525. {
  1526. FW_UNUSED(ev);
  1527. FW_UNUSED(storageUnitView);
  1528.     // For subclasses
  1529. }
  1530.  
  1531. //----------------------------------------------------------------------------------------
  1532. //    FW_CFrame::PrivExternalizeFrame
  1533. //----------------------------------------------------------------------------------------
  1534.  
  1535. void FW_CFrame::PrivExternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  1536. {
  1537.     // ----- Write first a version number
  1538.     FW_CByteArray byteArray(&FW_kFrameVersion, sizeof(FW_FrameVersion));
  1539.     storageUnitView->SetValue(ev, byteArray);
  1540.  
  1541.     // ----- Write content view offset
  1542.     byteArray.Set(&fContentViewOffset, sizeof(fContentViewOffset));
  1543.     storageUnitView->SetValue(ev, byteArray);
  1544.  
  1545.     // ----- Write requestedFrame flag
  1546.     byteArray.Set(&fRequestedFrame, sizeof(fRequestedFrame));
  1547.     storageUnitView->SetValue(ev, byteArray);
  1548. }
  1549.  
  1550. //----------------------------------------------------------------------------------------
  1551. //    FW_CFrame::PrivInternalizeFrame
  1552. //----------------------------------------------------------------------------------------
  1553.  
  1554. void FW_CFrame::PrivInternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  1555. {
  1556.     FW_CByteArray byteArray;
  1557.  
  1558.     // ----- Read first a version number
  1559.     FW_FrameVersion version;
  1560.     storageUnitView->GetValue(ev, sizeof(FW_FrameVersion), byteArray);
  1561.     byteArray.CopyBuffer(&version, sizeof(FW_FrameVersion));
  1562.     FW_ASSERT(version == FW_kFrameVersion);
  1563.     
  1564.     // ----- Read content view offset
  1565.     storageUnitView->GetValue(ev, sizeof(fContentViewOffset), byteArray);
  1566.     byteArray.CopyBuffer(&fContentViewOffset, sizeof(fContentViewOffset));
  1567.     
  1568.     // ----- Read requestedFrame flag
  1569.     storageUnitView->GetValue(ev, sizeof(fRequestedFrame), byteArray);
  1570.     byteArray.CopyBuffer(&fRequestedFrame, sizeof(fRequestedFrame));
  1571.     
  1572.     // ----- The Internal transform needs to be realign because
  1573.     // the view layout may have changed
  1574.     fInternalTransformRealigmentNeeded = TRUE;
  1575. }
  1576.  
  1577. //----------------------------------------------------------------------------------------
  1578. //    FW_CFrame::GetContentExtent
  1579. //----------------------------------------------------------------------------------------
  1580.  
  1581. void FW_CFrame::GetContentExtent(Environment* ev, FW_CPoint& extent) const
  1582. {
  1583.     extent = GetContentView(ev)->GetExtent(ev);
  1584. }
  1585.  
  1586. //----------------------------------------------------------------------------------------
  1587. //    FW_CFrame::AcquireContentShape
  1588. //----------------------------------------------------------------------------------------
  1589. //    return the content shape in Frame coordinates
  1590.  
  1591. ODShape* FW_CFrame::AcquireContentShape(Environment *ev)
  1592. {    
  1593.     if (fContentShape == NULL)
  1594.     {
  1595.         FW_CSuperView* contentView = GetContentView(ev);
  1596.         
  1597.         FW_CRect contentRect(contentView->GetBounds(ev));
  1598.         
  1599.         FW_CSuperView* superView = contentView->GetSuperView(ev);
  1600.         if (superView)
  1601.             superView->ViewContentToFrame(ev, contentRect);
  1602.         
  1603.         fContentShape = FW_NewODShape(ev, contentRect);
  1604.     }
  1605.     
  1606.     fContentShape->Acquire(ev);
  1607.     
  1608.     return fContentShape;
  1609. }
  1610.  
  1611. //----------------------------------------------------------------------------------------
  1612. //    FW_CFrame::PrivContentShapeChanged
  1613. //----------------------------------------------------------------------------------------
  1614. //    The content shape has changed (usually because the content view bounds has changed)
  1615.  
  1616. void FW_CFrame::PrivContentShapeChanged(Environment *ev)
  1617. {
  1618.     if (fContentShape)
  1619.     {
  1620.         fContentShape->Release(ev);
  1621.         fContentShape = NULL;
  1622.     }
  1623. }
  1624.  
  1625. //----------------------------------------------------------------------------------------
  1626. //    FW_CFrame::GetFocusSet
  1627. //----------------------------------------------------------------------------------------
  1628.  
  1629. ODFocusSet* FW_CFrame::GetFocusSet(Environment* ev) const
  1630. {
  1631.     return fPresentation->GetFocusSet(ev);
  1632. }
  1633.  
  1634. //----------------------------------------------------------------------------------------
  1635. //    FW_CFrame::BeginRelinquishFocus
  1636. //----------------------------------------------------------------------------------------
  1637.  
  1638. FW_Boolean FW_CFrame::BeginRelinquishFocus(Environment *ev, ODTypeToken focus, ODFrame* proposedFrame)
  1639. {
  1640. FW_UNUSED(ev);
  1641. FW_UNUSED(focus);
  1642. FW_UNUSED(proposedFrame);
  1643.     // Only relinquish the scrolling focus in the proposedFrame is in another window or is one
  1644.     // of my parent frame
  1645.     FW_Boolean result = TRUE;
  1646.     
  1647.     if (focus == FW_CPart::fgScrollingFocusToken)
  1648.     {
  1649.         FW_CAcquiredODWindow proposedODWindow = proposedFrame->AcquireWindow(ev);
  1650.         FW_CAcquiredODWindow aqODWindow = this->AcquireODWindow(ev);
  1651.         if (proposedODWindow == aqODWindow)    // same window try parent frame
  1652.         {    
  1653.             result = FALSE;    
  1654.             FW_CAcquiredODFrame aFrame = fODFrame->AcquireContainingFrame(ev);
  1655.             while ((const void*)aFrame != NULL)
  1656.             {
  1657.                 if (aFrame == proposedFrame)
  1658.                 {
  1659.                     result = TRUE;
  1660.                     break;
  1661.                 }
  1662.                 
  1663.                 aFrame = aFrame->AcquireContainingFrame(ev);
  1664.             }
  1665.         }    
  1666.     }
  1667.     
  1668.     return result;
  1669. }
  1670.  
  1671. //----------------------------------------------------------------------------------------
  1672. //    FW_CFrame::AbortRelinquishFocus
  1673. //----------------------------------------------------------------------------------------
  1674.  
  1675. void FW_CFrame::AbortRelinquishFocus(Environment *ev, ODTypeToken focus, ODFrame* proposedFrame)
  1676. {
  1677. FW_UNUSED(ev);
  1678. FW_UNUSED(focus);
  1679. FW_UNUSED(proposedFrame);
  1680. }
  1681.  
  1682. //----------------------------------------------------------------------------------------
  1683. //    FW_CFrame::ClonePartInfo
  1684. //----------------------------------------------------------------------------------------
  1685.  
  1686. void FW_CFrame::ClonePartInfo(Environment* ev, 
  1687.                             ODDraftKey key,
  1688.                             ODInfoType partInfo,
  1689.                             ODStorageUnitView* storageUnitView,
  1690.                             ODFrame* scope)
  1691. {
  1692. FW_UNUSED(key);
  1693. FW_UNUSED(partInfo);
  1694. FW_UNUSED(scope);
  1695.     
  1696.     // ----- By default just call externalizeFrame -----
  1697.     ExternalizeFrame(ev, storageUnitView);
  1698. }
  1699.  
  1700. #ifdef FW_BUILD_WIN
  1701. //----------------------------------------------------------------------------------------
  1702. //    FW_CFrame::CreateShadowWindow
  1703. //----------------------------------------------------------------------------------------
  1704. // Create a transparent Window so that we get a chance to handle messages sent by Windows
  1705. // controls to their parent Window.
  1706.  
  1707. void FW_CFrame::CreateShadowWindow(Environment *ev)
  1708. {
  1709.     ODPlatformWindow parentHWnd = fWindow->GetPlatformWindow(ev);
  1710. #ifdef FW_BUILD_WIN16
  1711.     HINSTANCE hInstance = (HINSTANCE)GetWindowWord(parentHWnd, GWW_HINSTANCE);
  1712. #endif
  1713. #ifdef FW_BUILD_WIN32
  1714.     HINSTANCE hInstance = (HINSTANCE)GetWindowLong(parentHWnd, GWL_HINSTANCE);
  1715. #endif
  1716.     
  1717.     WNDCLASS wc;
  1718.     
  1719.     if (!GetClassInfo(hInstance, "ShadowWindow", &wc))
  1720.     {
  1721.         wc.style = CS_DBLCLKS;
  1722.         wc.lpfnWndProc = ShadowWindowProc;
  1723.         wc.cbClsExtra = 0;
  1724.         wc.cbWndExtra = 4;
  1725.         wc.hInstance = hInstance;
  1726.         wc.hIcon = NULL;
  1727.         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  1728.         wc.hbrBackground = NULL;
  1729.         wc.lpszMenuName = NULL;
  1730.         wc.lpszClassName = "ShadowWindow";
  1731.         
  1732.         if (!RegisterClass(&wc))
  1733.             return;
  1734.     }
  1735.     
  1736.     fShadowWindow = CreateWindowEx(WS_EX_TRANSPARENT, "ShadowWindow", "",
  1737.                                    WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
  1738.                                    parentHWnd, NULL, hInstance, (LPSTR) this);
  1739.     MoveSizeShadowWindow(ev);
  1740. }
  1741. #endif
  1742.  
  1743. #ifdef FW_BUILD_WIN
  1744. //----------------------------------------------------------------------------------------
  1745. //    FW_CFrame::MoveSizeShadowWindow
  1746. //----------------------------------------------------------------------------------------
  1747.  
  1748. void FW_CFrame::MoveSizeShadowWindow(Environment* ev)
  1749. {
  1750.     if (fShadowWindow != NULL)
  1751.     {
  1752.         ODFacet* facet = GetActiveFacet(ev);
  1753.         FW_CAcquiredODShape aqShape(FW_CopyAndRelease(ev, facet->AcquireActiveShape(ev, NULL)));
  1754.         FW_CAcquiredODTransform aqExternalTransform = facet->AcquireExternalTransform(ev, NULL);
  1755.         aqShape->Transform(ev, aqExternalTransform);
  1756.         
  1757.         FW_CRect bBox;
  1758.         aqShape->GetBoundingBox(ev, &bBox);
  1759.         
  1760.         // Shape bounding box is in 72dpi, need to convert to pixels
  1761.         if(!IsRoot(ev))
  1762.         {
  1763.             // [KVV] ??? This is only necessary for non-root frames
  1764.         
  1765.             HDC hDC = ::GetDC(NULL);
  1766.             int xRes = ::GetDeviceCaps(hDC, LOGPIXELSX);
  1767.             int yRes = ::GetDeviceCaps(hDC, LOGPIXELSY);
  1768.             ::ReleaseDC(NULL, hDC);
  1769.             
  1770.             FW_Fixed xScale = FW_FixDiv(ff(xRes), ff(72));
  1771.             FW_Fixed yScale = FW_FixDiv(ff(yRes), ff(72));
  1772.             
  1773.             bBox.left     = FW_FixMul(bBox.left,    xScale);
  1774.             bBox.top     = FW_FixMul(bBox.top,    yScale);
  1775.             bBox.right     = FW_FixMul(bBox.right,    xScale);
  1776.             bBox.bottom    = FW_FixMul(bBox.bottom,yScale);
  1777.         }
  1778.         
  1779.         FW_PlatformRect wndRect = bBox.AsPlatformRect();
  1780.         
  1781.         ::MoveWindow(fShadowWindow, wndRect.left, wndRect.top,
  1782.                        wndRect.right - wndRect.left, wndRect.bottom - wndRect.top, TRUE);
  1783.     }
  1784. }
  1785. #endif
  1786.  
  1787. #ifdef FW_BUILD_WIN
  1788. //----------------------------------------------------------------------------------------
  1789. //    FW_CFrame::ShadowWindowProc
  1790. //----------------------------------------------------------------------------------------
  1791.  
  1792. LRESULT CALLBACK FW_CFrame::ShadowWindowProc(HWND hWnd, UINT msg,
  1793.                                              WPARAM wParam, LPARAM lParam)
  1794. {
  1795.     switch (msg)
  1796.     {
  1797. #ifdef FW_DEBUG
  1798.         // ----- Frame the shadow window for ease of debugging
  1799.         case WM_PAINT:
  1800.             {
  1801.                 PAINTSTRUCT ps;
  1802.                 HDC hDC = ::BeginPaint(hWnd, &ps);
  1803.                 
  1804.                 if(::GetPrivateProfileInt("Debug", "ShadowWindow Outline", FALSE, "ODF.ini"))
  1805.                 {
  1806.                     static const char pattern[8][2] = 
  1807.                     {
  1808.                         { 0xAA, 0x00 },
  1809.                         { 0x55, 0x00 },
  1810.                         { 0xAA, 0x00 },
  1811.                         { 0x55, 0x00 },
  1812.                         { 0xAA, 0x00 },
  1813.                         { 0x55, 0x00 },
  1814.                         { 0xAA, 0x00 },
  1815.                         { 0x55, 0x00 }
  1816.                     };
  1817.                     
  1818.                     HBITMAP hBitmap = ::CreateBitmap(8, 8, 1, 1, pattern);
  1819.     
  1820.                     HBRUSH hBrush = ::CreatePatternBrush(hBitmap);
  1821.     
  1822.                     ::SetTextColor(hDC, RGB(0xFF, 0x00, 0xFF));
  1823.                     
  1824.                     RECT rc;
  1825.                     ::GetClientRect(hWnd, &rc);
  1826.                     
  1827.                     HRGN hRgn = ::CreateRectRgnIndirect(&rc);
  1828.                     
  1829.                     ::FrameRgn(hDC, hRgn, hBrush, 3, 3);
  1830.                     
  1831.                     ::DeleteObject(hRgn);
  1832.                     ::DeleteObject(hBrush);
  1833.                     ::DeleteObject(hBitmap);
  1834.                 }
  1835.  
  1836.                 ::EndPaint(hWnd, &ps);
  1837.             }
  1838.             return 0;
  1839. #endif
  1840.  
  1841.         case WM_CREATE:
  1842.             SetWindowLong(hWnd, 0, (long) ((LPCREATESTRUCT) lParam)->lpCreateParams);
  1843.             return 0;
  1844.             
  1845.         case WM_NCHITTEST:
  1846.             return HTTRANSPARENT;
  1847.             
  1848.         case WM_COMMAND:
  1849.             switch (HIWORD(wParam))
  1850.             {
  1851.                 case BN_CLICKED:
  1852.                     {
  1853.                         HWND hButton = HWND(lParam);
  1854.                         
  1855.                         // If this is a window
  1856.                         if (hButton != NULL && ::IsWindow(hButton))
  1857.                         {
  1858.                             // Get the scroll bar helper
  1859.                             FW_CPrivWinButtonHelper* buttonHelper =
  1860.                                 FW_DYNAMIC_CAST(FW_CPrivWinButtonHelper, FW_CPrivWinControlHelper::HWNDToHelper(hButton));
  1861.         
  1862.                             // Tell the button to update itself and the pane
  1863.                             buttonHelper->HandleButtonMessage();
  1864.                             return 0L;
  1865.                         }
  1866.                     }
  1867.                     break;
  1868.             }
  1869.             break;
  1870.             
  1871.         case WM_HSCROLL:
  1872.         case WM_VSCROLL:
  1873.             {
  1874.                 HWND hBar = HWND(lParam);
  1875.  
  1876.                 // If this is not a scroll bar control, but a Windows
  1877.                 // window scroll bar, pass it to Windows wndproc
  1878.                 if (hBar == NULL)
  1879.                 {
  1880.                     FW_DEBUG_MESSAGE("Warning: ODF does not use Window scroll bars!");
  1881.                     break;
  1882.                 }
  1883.  
  1884.                 // If this is a window
  1885.                 if (hBar != NULL && ::IsWindow(hBar))
  1886.                 {
  1887.                     // Get the scroll bar helper
  1888.                     FW_CPrivWinScrollBarHelper* sbHelper =
  1889.                         FW_DYNAMIC_CAST(FW_CPrivWinScrollBarHelper, FW_CPrivWinControlHelper::HWNDToHelper(hBar));
  1890.  
  1891.                     // Tell the scroll bar to update itself and the pane
  1892.                     if (sbHelper != NULL)
  1893.                     {
  1894.                         sbHelper->HandleScrollMessage(LOWORD(wParam), HIWORD(wParam));
  1895.                         return 0L;
  1896.                     }
  1897.                 }
  1898.                 break;
  1899.             }
  1900.     }
  1901.     
  1902.     return DefWindowProc(hWnd, msg, wParam, lParam);
  1903. }
  1904. #endif
  1905.  
  1906. //----------------------------------------------------------------------------------------
  1907. //    FW_CFrame::HasModalFocus
  1908. //----------------------------------------------------------------------------------------
  1909.  
  1910. FW_Boolean FW_CFrame::HasModalFocus(Environment* ev) const
  1911. {
  1912.     FW_CAcquiredODFrame aqODFrame = FW_CSession::GetArbitrator(ev)->AcquireFocusOwner(ev, FW_CPart::fgModalFocusToken);
  1913.     return aqODFrame == fODFrame;
  1914. }
  1915.  
  1916. //----------------------------------------------------------------------------------------
  1917. //    FW_CFrame::HasPropertyOnClipboard
  1918. //----------------------------------------------------------------------------------------
  1919.  
  1920. FW_Boolean FW_CFrame::HasPropertyOnClipboard(Environment* ev, ODPropertyName propertyName, ODValueType type) const
  1921. {
  1922.     FW_Boolean result = FALSE;
  1923.     ODArbitrator* arbitrator = FW_CSession::GetArbitrator(ev);
  1924.     FW_CAcquiredODFrame aqODFrame = arbitrator->AcquireFocusOwner(ev, FW_CPart::fgClipboardFocusToken);
  1925.     
  1926.     if ((aqODFrame == fODFrame) || (arbitrator->RequestFocus(ev, FW_CPart::fgClipboardFocusToken, fODFrame)) )
  1927.     {    
  1928.         ODStorageUnit* su = FW_CSession::GetClipboard(ev)->GetContentStorageUnit(ev);
  1929.         result = su->Exists(ev, propertyName, type, 0);
  1930.     }
  1931.     
  1932.     return result;
  1933. }
  1934.  
  1935. //----------------------------------------------------------------------------------------
  1936. //    FW_CFrame::HasSupportedKindOnClipboard
  1937. //----------------------------------------------------------------------------------------
  1938.  
  1939. FW_Boolean FW_CFrame::HasSupportedKindOnClipboard(Environment* ev) const
  1940. {
  1941.     FW_Boolean result = FALSE;
  1942.     ODArbitrator* arbitrator = FW_CSession::GetArbitrator(ev);
  1943.     FW_CAcquiredODFrame aqODFrame = arbitrator->AcquireFocusOwner(ev, FW_CPart::fgClipboardFocusToken);
  1944.     
  1945.     if ((aqODFrame == fODFrame) || (arbitrator->RequestFocus(ev, FW_CPart::fgClipboardFocusToken, fODFrame)) )
  1946.     {    
  1947.         ODStorageUnit* su = FW_CSession::GetClipboard(ev)->GetContentStorageUnit(ev);
  1948.         result = (GetPart(ev)->GetSupportedKind(ev, su, FW_kClipboardStorage) != NULL);
  1949.     }
  1950.     
  1951.     return result;
  1952. }
  1953.  
  1954. //----------------------------------------------------------------------------------------
  1955. //    FW_CFrame::PrivChangeInternalTransform
  1956. //----------------------------------------------------------------------------------------
  1957.  
  1958. void FW_CFrame::PrivChangeInternalTransform(Environment* ev, ODTransform* internalTransform, ODCanvas* biasCanvas)
  1959. {
  1960.     // *LSD2  hack can be removed after DR4 ?
  1961. #ifdef FW_BUILD_MAC
  1962.     // [HLX] Temporary because of a bug in OpenDoc
  1963.     //    ODFFrame::ChangeInternalTransform changes the clip and the origin and does not restore it
  1964.     GrafPtr port;
  1965.     ::GetPort(&port);    
  1966.     Point origin;
  1967.     origin.h = port->portRect.left;
  1968.     origin.v = port->portRect.top;
  1969.     ODRgnHandle clipRgn = ::FW_NewRegion();
  1970.     ::GetClip(clipRgn);
  1971. #endif
  1972.     
  1973.     fODFrame->ChangeInternalTransform(ev, internalTransform, biasCanvas);
  1974.  
  1975. #ifdef FW_BUILD_MAC
  1976.     // [HLX] Temporary because of a bug in OpenDoc
  1977.     ::SetPort(port);
  1978.     ::SetClip(clipRgn);
  1979.     ::FW_DisposeRegion(clipRgn);
  1980.     ::SetOrigin(-origin.h, -origin.v);
  1981. #endif
  1982.     
  1983.     // Now invalidate all the views Internal transforms
  1984.     PrivInvalidateViewIternalTransform(ev);
  1985. }
  1986.  
  1987. //----------------------------------------------------------------------------------------
  1988. //    FW_CFrame::SynchContainingPartProperties
  1989. //----------------------------------------------------------------------------------------
  1990.  
  1991. void FW_CFrame::SynchContainingPartProperties(Environment* ev)
  1992. {
  1993.     if (!IsRoot(ev))
  1994.     {
  1995.         FW_CAcquiredODStorageUnit aqPropertyUnit;
  1996.         FW_CAcquiredODFrame aqContainingFrame = AcquireContainingFrame(ev);
  1997.         
  1998.         if (aqContainingFrame != NULL)
  1999.         {
  2000.             FW_CAcquiredODPart aqContainingPart = aqContainingFrame->AcquirePart(ev);
  2001.             aqPropertyUnit = aqContainingPart->AcquireContainingPartProperties(ev, GetODFrame(ev));
  2002.         }
  2003.         
  2004.         AdoptContainingPartProperties(ev, aqPropertyUnit);
  2005.     }
  2006. }
  2007.  
  2008. //----------------------------------------------------------------------------------------
  2009. //    FW_CFrame::AdoptContainingPartProperties
  2010. //----------------------------------------------------------------------------------------
  2011.  
  2012. void FW_CFrame::AdoptContainingPartProperties(Environment *ev, ODStorageUnit* propertyUnit)
  2013. {
  2014. FW_UNUSED(ev);
  2015. FW_UNUSED(propertyUnit);
  2016. }
  2017.  
  2018. //----------------------------------------------------------------------------------------
  2019. //    FW_CFrame::NewPrintHandler
  2020. //----------------------------------------------------------------------------------------
  2021.  
  2022. FW_CPrintHandler* FW_CFrame::NewPrintHandler(Environment* ev)
  2023. {
  2024. FW_UNUSED(ev);
  2025.  
  2026.     return NULL;
  2027. }
  2028.  
  2029. //----------------------------------------------------------------------------------------
  2030. // FW_CFrame::SetLocation
  2031. //----------------------------------------------------------------------------------------
  2032.  
  2033. void FW_CFrame::SetLocation(Environment* ev, const FW_CPoint& location, FW_ERedrawVerb redraw)
  2034. {
  2035. FW_UNUSED(ev);
  2036. FW_UNUSED(location);
  2037. FW_UNUSED(redraw);
  2038.  
  2039.     FW_DEBUG_MESSAGE("Can't call SetLocation on a FW_CFrame");
  2040. }
  2041.  
  2042. //----------------------------------------------------------------------------------------
  2043. //     FW_CFrame::RelinquishFocusSet
  2044. //----------------------------------------------------------------------------------------
  2045. //    Usually should not have to be overriden. Can be overriden for special case
  2046.  
  2047. void FW_CFrame::RelinquishFocusSet(Environment *ev)
  2048. {
  2049.     FW_ASSERT(GetFocusSet(ev) != NULL);
  2050.     
  2051.     ODArbitrator* arbitrator = FW_CSession::GetArbitrator(ev);
  2052.     arbitrator->RelinquishFocusSet(ev, GetFocusSet(ev), GetODFrame(ev));
  2053.     if (fHasScrollingFocus)
  2054.     {
  2055.         arbitrator->RelinquishFocus(ev, FW_CPart::fgScrollingFocusToken, GetODFrame(ev));
  2056.         fHasScrollingFocus = FALSE;
  2057.         fNeedsScrollingFocus = TRUE;
  2058.     }
  2059. }
  2060.  
  2061. //----------------------------------------------------------------------------------------
  2062. //     FW_CFrame::RequestFocusSet
  2063. //----------------------------------------------------------------------------------------
  2064. //    Usually should not have to be overriden. Can be overriden for special case
  2065.  
  2066. FW_Boolean FW_CFrame::RequestFocusSet(Environment *ev)
  2067. {
  2068.     FW_ASSERT(GetFocusSet(ev) != NULL);
  2069.  
  2070.     ODArbitrator* arbitrator = FW_CSession::GetArbitrator(ev);
  2071.     return arbitrator->RequestFocusSet(ev, GetFocusSet(ev), GetODFrame(ev));
  2072. }
  2073.  
  2074. //----------------------------------------------------------------------------------------
  2075. //     FW_CFrame::PrivRequestScrollingFocus
  2076. //----------------------------------------------------------------------------------------
  2077.  
  2078. void FW_CFrame::PrivRequestScrollingFocus(Environment *ev)
  2079. {
  2080.     if (!fHasScrollingFocus)
  2081.     {
  2082.         ODArbitrator* arbitrator = FW_CSession::GetArbitrator(ev);
  2083.         if (arbitrator->RequestFocus(ev, FW_CPart::fgScrollingFocusToken, GetODFrame(ev)))
  2084.         {
  2085.             fNeedsScrollingFocus = FALSE;
  2086.             FocusStateChanged(ev, FW_CPart::fgScrollingFocusToken, TRUE, NULL);
  2087.         }
  2088.     }
  2089. }
  2090.  
  2091. //----------------------------------------------------------------------------------------
  2092. // FW_CFrame::HandleIdle
  2093. //----------------------------------------------------------------------------------------
  2094.  
  2095. FW_Handled FW_CFrame::HandleIdle(Environment* ev, const FW_CNullEvent& theNullEvent)
  2096. {
  2097.     if (IsInLimbo(ev)) 
  2098.         return FW_kNotHandled;        // don't idle if we're in limbo
  2099.  
  2100.     return DoIdle(ev, theNullEvent);    
  2101. }
  2102.  
  2103. //----------------------------------------------------------------------------------------
  2104. // FW_CFrame::IsFrameInLinkDestination
  2105. //----------------------------------------------------------------------------------------
  2106. FW_Boolean FW_CFrame::IsFrameInLinkDestination(Environment* ev)
  2107. {
  2108.     FW_Boolean result = GetODFrame(ev)->GetLinkStatus(ev) == kODInLinkDestination;
  2109.     if (result)
  2110.     {
  2111.         // user is trying to edit inside a link destination
  2112.         if (GetODFrame(ev)->EditInLink(ev))         // brings up EditInLinkAttempted dialog in containing  part
  2113.         {
  2114.             result = GetODFrame(ev)->GetLinkStatus(ev) == kODInLinkDestination;  // changed if user broke the link
  2115.         }
  2116.         else
  2117.         {
  2118.             // Inform user that link cannot be edited
  2119.             fPart->PrivShowErrorAlert(ev, FW_kLinkingStrings, FW_kCantEditThisLinkMsg);
  2120.         }
  2121.     }
  2122.  
  2123.     return result;
  2124. }
  2125.  
  2126. //----------------------------------------------------------------------------------------
  2127. //    FW_CFrame::CanvasChanged
  2128. //----------------------------------------------------------------------------------------
  2129.  
  2130. void FW_CFrame::CanvasChanged(Environment* ev, ODFacet* facet)
  2131. {
  2132.     FW_HGDevice graphicDevice = FW_GetFacetGraphicDevice(ev, facet);
  2133.     if(graphicDevice != NULL)
  2134.         FW_PrivGDev_CanvasChanged(graphicDevice, ev, facet->GetCanvas(ev));
  2135. }    
  2136.  
  2137. //----------------------------------------------------------------------------------------
  2138. //     FW_CFrame::ActivateFrame
  2139. //----------------------------------------------------------------------------------------
  2140. //    activatedFacet can be NULL. Will use the current active facet or the firts facet.
  2141.  
  2142. void FW_CFrame::ActivateFrame(Environment *ev, ODFacet* activatedFacet)
  2143. //    if (fShowPaletteOnMouseUp)
  2144. //    {
  2145. //        FW_CFloatingWindow::HideShowFloatingWindows(ev, TRUE, fPart->GetODPart(ev));
  2146. //        fShowPaletteOnMouseUp = FALSE;
  2147. //    }
  2148.         
  2149.     if (CanBeActiveFrame(ev))
  2150.     {
  2151.         if (activatedFacet == NULL)
  2152.         {
  2153.             ODFacet* aFacet = GetActiveFacet(ev);
  2154.             if (aFacet == NULL)
  2155.             {
  2156.                 FW_CFrameFacetIterator iter(ev, this);    // find a facet
  2157.                 activatedFacet = iter.First(ev);
  2158.             }
  2159.             //     if aFacet != NULL (there is an active facet already) it means that 
  2160.             //    activatedFacet will be equal to NULL and we are not going to call SetActiveFacet 
  2161.         }
  2162.         
  2163.         if (activatedFacet != NULL)
  2164.             SetActiveFacet(ev, activatedFacet);
  2165.         
  2166.         if (fHasSelectionFocus == FALSE)
  2167.         {
  2168.             if (RequestFocusSet(ev))
  2169.             {
  2170.                 fNeedsFoci = FALSE;
  2171.                 
  2172.                 FW_CFocusSetIterator iter(ev, this);
  2173.                 for( ODTypeToken token=iter.First(ev); iter.IsNotComplete(ev); token=iter.Next(ev) ) {
  2174.                     FocusStateChanged(ev, token, TRUE, NULL);            
  2175.                 }
  2176.                 
  2177.                 // Try the scrolling focus
  2178.                 if (fScroller && fScroller->IsHandlingPageNavigationKeys(ev))
  2179.                     PrivRequestScrollingFocus(ev);
  2180.                     
  2181.                 ::FW_ForceAdjustCursor(ev);
  2182.             }
  2183.         }
  2184.     }
  2185. }
  2186.  
  2187. //----------------------------------------------------------------------------------------
  2188. //    FW_CFrame::Reveal
  2189. //----------------------------------------------------------------------------------------
  2190. //    Reveal will ask the container (if any) to reveal shapeToReveal which is in frame coordinates
  2191.  
  2192. FW_Boolean FW_CFrame::Reveal(Environment* ev, ODShape* shapeToReveal)
  2193. {
  2194.     FW_CAcquiredODFrame aqContainingFrame = AcquireContainingFrame(ev);
  2195.     if ((const void*)aqContainingFrame != NULL)
  2196.     {
  2197.         FW_CAcquiredODShape tempShape; 
  2198.         if (shapeToReveal == NULL)
  2199.             tempShape = FW_CopyAndRelease(ev, AcquireFrameShape(ev));
  2200.         else
  2201.         {
  2202.             shapeToReveal->Acquire(ev);
  2203.             tempShape = shapeToReveal;
  2204.         }
  2205.     
  2206.         FW_CAcquiredODPart containingPart = aqContainingFrame->AcquirePart(ev);
  2207.         return containingPart->RevealFrame(ev, GetODFrame(ev), tempShape);
  2208.     }
  2209.     
  2210.     return FALSE;
  2211. }
  2212.  
  2213. //========================================================================================
  2214. // Implementation Only API
  2215. //========================================================================================
  2216.  
  2217. //----------------------------------------------------------------------------------------
  2218. //    FW_CFrame::PrivCreateWindow
  2219. //----------------------------------------------------------------------------------------
  2220.  
  2221. FW_CWindow* FW_CFrame::PrivCreateWindow(Environment* ev, ODWindow* odWindow)
  2222. {
  2223.     FW_ASSERT(odWindow);
  2224. //    FW_ASSERT(fWindow == NULL || fWindow->GetID(ev) == odWindow->GetID(ev));
  2225.     
  2226.     // ----- Test first if this frame was in another window -----
  2227.     if (fWindow != NULL && fWindow->GetID(ev) != odWindow->GetID(ev))
  2228.     {
  2229.         delete fWindow;
  2230.         fWindow = NULL;
  2231.     }
  2232.     
  2233.     if (fWindow == NULL)
  2234.     {
  2235.         ODPlatformWindow platformWindow = odWindow->GetPlatformWindow(ev);
  2236.         
  2237.         FW_CWindow* fwWindow = NULL;
  2238.         
  2239.         if (IsRoot(ev))
  2240.         {
  2241. #ifdef FW_BUILD_MAC
  2242.             fwWindow = (FW_CWindow*) ::GetWRefCon(platformWindow);
  2243. #endif
  2244.  
  2245. #ifdef FW_BUILD_WIN
  2246.             fwWindow = (FW_CWindow*) ::GetProp(platformWindow, "ODF:Window");
  2247. #endif
  2248.         }
  2249.         
  2250.         if (fwWindow != NULL)
  2251.             fWindow = fwWindow;
  2252.         else
  2253.             fWindow = new FW_CWindow(ev, odWindow->GetID(ev));
  2254.     }
  2255.  
  2256.     fInSharedWindow = IsRoot(ev) && fWindow->IsFloating(ev);
  2257.     
  2258.     return fWindow;
  2259. }
  2260.  
  2261. //----------------------------------------------------------------------------------------
  2262. //    FW_CFrame::PrivSetDroppable
  2263. //----------------------------------------------------------------------------------------
  2264.  
  2265. void FW_CFrame::PrivSetDroppable(Environment *ev, FW_MDroppableFrame* droppable, FW_Boolean isDroppable)
  2266. {
  2267.     fDroppable = droppable;
  2268.     fODFrame->SetDroppable(ev, isDroppable);
  2269. }
  2270.  
  2271. #ifdef FW_BUILD_MAC
  2272. //----------------------------------------------------------------------------------------
  2273. //    FW_CFrame::PrivMacInGrowBox
  2274. //----------------------------------------------------------------------------------------
  2275.  
  2276.  void FW_CFrame::PrivMacInGrowBox(Environment* ev, const FW_CMacWindowEvent& windowEvent)
  2277.  {    
  2278.     FW_CRect growLimits(FW_IntToFixed(64), FW_IntToFixed(64), FW_IntToFixed(32000), FW_IntToFixed(32000));
  2279.     this->AdjustWindowGrowLimits(ev, growLimits[FW_kTopLeft], growLimits[FW_kBotRight]);
  2280.     
  2281.     // If minimum is lareger than maximun then do something
  2282.     if (growLimits.left > growLimits.right)
  2283.         growLimits.left = growLimits.right;
  2284.     if (growLimits.top > growLimits.bottom)
  2285.         growLimits.top = growLimits.bottom;
  2286.     
  2287.      ODEventData* eventData = ((FW_CMacWindowEvent&)windowEvent).GetPlatformEvent();
  2288.      FW_CAcquiredODWindow aqODWindow = fWindow->AcquireODWindow(ev);
  2289.     
  2290. //    growLimits.right += FW_kFixedPos1;
  2291. //    growLimits.bottom += FW_kFixedPos1;
  2292.     
  2293.     FW_PlatformError error;
  2294.     FW_Boolean result = FW_PrivMacTrackResizeWindow(aqODWindow->GetPlatformWindow(ev), 
  2295.                                      growLimits,
  2296.                                      eventData->where,
  2297.                                      &error);
  2298.      FW_FailOnError(error);
  2299.      if (result)
  2300.         aqODWindow->AdjustWindowShape(ev);
  2301. }
  2302. #endif
  2303.  
  2304. //----------------------------------------------------------------------------------------
  2305. //    FW_CFrame::PrivGetFrameShapeBounds
  2306. //----------------------------------------------------------------------------------------
  2307.  
  2308. void FW_CFrame::PrivGetFrameShapeBounds(Environment* ev, FW_CRect& rect) const
  2309. {
  2310.     FW_CAcquiredODShape aqODShape = AcquireFrameShape(ev, NULL);
  2311.     rect = FW_GetShapeBoundingBox(ev, aqODShape);
  2312. }
  2313.  
  2314. //----------------------------------------------------------------------------------------
  2315. //     FW_CFrame::PrivFacetRemoved
  2316. //----------------------------------------------------------------------------------------
  2317.  
  2318. void FW_CFrame::PrivFacetRemoved(Environment* ev, ODFacet* facet)
  2319. {
  2320.     FW_ASSERT(fFacetCount > 0);
  2321.     
  2322.     FacetRemoved(ev, facet, fFacetCount);
  2323.     
  2324.     // ----- One less facet -----
  2325.     fFacetCount--;
  2326. }
  2327.  
  2328. //----------------------------------------------------------------------------------------
  2329. //     FW_CFrame::PrivFacetAdded
  2330. //----------------------------------------------------------------------------------------
  2331.  
  2332. void FW_CFrame::PrivFacetAdded(Environment* ev, ODFacet* facet)
  2333. {
  2334.     // ----- One more facet -----
  2335.     fFacetCount++;    
  2336.  
  2337.     FacetAdded(ev, facet, fFacetCount);
  2338. }
  2339.  
  2340. //----------------------------------------------------------------------------------------
  2341. //    FW_CFrame::PrivAttachSourceFrame
  2342. //----------------------------------------------------------------------------------------
  2343. //    FW_CFrame::PrivAttachSourceFrame should not be called if sourceFrame == NULL
  2344.  
  2345. void FW_CFrame::PrivAttachSourceFrame(Environment* ev, FW_CFrame* sourceFrame)
  2346. {
  2347.     FW_ASSERT(sourceFrame != NULL);
  2348.     FW_ASSERT(fSourceFrame == this);    // fSourceFrame is set to this in the constructor
  2349.     
  2350.     fSourceFrame = sourceFrame->GetSourceFrame(ev);
  2351. }
  2352.  
  2353. //----------------------------------------------------------------------------------------
  2354. //     FW_CFrame::ActivateWindow
  2355. //----------------------------------------------------------------------------------------
  2356. //    Return TRUE if the frame doesn't handle front click meaning that a mouse down event
  2357. //     should not be sent to it.
  2358.  
  2359. FW_Boolean FW_CFrame::ActivateWindow(Environment* ev, ODFacet* facet, FW_Boolean activateFrame)
  2360. {
  2361.     if (!GetWindow(ev)->IsFloating(ev))
  2362.     {
  2363.         FW_Boolean windowUnselected = !GetWindow(ev)->IsActive(ev);
  2364.         
  2365.         // ----- Select the window if not already selected -----
  2366.         if (windowUnselected)
  2367.             GetWindow(ev)->Select(ev);        
  2368.         
  2369.         // ----- active frame on mousedown only if clicked in the frame -----
  2370.         if (activateFrame == TRUE /*&& fHasSelectionFocus == FALSE*/)
  2371.         {
  2372. //            fShowPaletteOnMouseUp = TRUE;
  2373.             ActivateFrame(ev, facet);
  2374.         }
  2375.         
  2376.         // ----- If the window was unselected and I don't want the ----- 
  2377.         // ----- first click just return TRUE;
  2378.         if (windowUnselected && !GetFrontClicks(ev))
  2379.             return TRUE;
  2380.     }
  2381.     
  2382.     return FALSE;
  2383. }
  2384.  
  2385. //----------------------------------------------------------------------------------------
  2386. //    FW_CFrame::PrivUpdateScrollParameters
  2387. //----------------------------------------------------------------------------------------
  2388.  
  2389. void FW_CFrame::PrivUpdateScrollParameters(Environment* ev)
  2390. {
  2391.     if (fScroller && !fInternalTransformRealigmentNeeded)
  2392.         fScroller->UpdateScrollParameters(ev);
  2393. }
  2394.  
  2395. //----------------------------------------------------------------------------------------
  2396. //    FW_CFrame::PrivContentViewLocationChanged
  2397. //----------------------------------------------------------------------------------------
  2398.  
  2399. void FW_CFrame::PrivContentViewLocationChanged(Environment* ev, const FW_CPoint& newLocation)
  2400. {
  2401.     if (fContentViewOffset != newLocation)
  2402.     {
  2403.         FW_CAcquiredODTransform aqFrameInternalTransform = AcquireInternalTransform(ev);
  2404.         aqFrameInternalTransform->MoveBy(ev, (ODPoint*)&(-fContentViewOffset));
  2405.         aqFrameInternalTransform->MoveBy(ev, (ODPoint*)&newLocation);
  2406.  
  2407.         //     fContentViewOffset must be set before calling PrivChangeInternalTransform because
  2408.         //    it might be used then
  2409.         fContentViewOffset = newLocation;
  2410.  
  2411.         PrivChangeInternalTransform(ev, aqFrameInternalTransform);    
  2412.     }
  2413. }
  2414.  
  2415. //----------------------------------------------------------------------------------------
  2416. // FW_CFrame::PrivRealignInternalTransform
  2417. //----------------------------------------------------------------------------------------
  2418. //    This is call when a document is reopened. Because the internal transform is saved by OpenDoc
  2419. //    and the InternalTransform contains the offset of the ContentView, if this offset is not
  2420. //    the same when the document is reopened I need to realign the Internal transform
  2421. void FW_CFrame::PrivRealignInternalTransform(Environment* ev)
  2422. {
  2423.     FW_ASSERT(fContentView);
  2424.     
  2425.     FW_CRect bounds = fContentView->GetBounds(ev);
  2426.     FW_CSuperView* contentViewParent = fContentView->GetSuperView(ev);
  2427.     if (contentViewParent)
  2428.         contentViewParent->ViewContentToFrame(ev, bounds);
  2429.     
  2430.     PrivContentViewLocationChanged(ev, bounds.TopLeft());
  2431.     
  2432.     fInternalTransformRealigmentNeeded = FALSE;
  2433.  
  2434.     if (fScroller)
  2435.         fScroller->PrivRealignScroller(ev);
  2436. }
  2437.  
  2438. //---------------------------------------------------------------------------------------
  2439. //    FW_CFrame::PrivStartStopDragging
  2440. //---------------------------------------------------------------------------------------
  2441.  
  2442. void FW_CFrame::PrivStartStopDragging(Environment *ev, FW_EPrivDraggingFlags dragFlags)
  2443. {
  2444. FW_UNUSED(ev);
  2445. FW_UNUSED(dragFlags);
  2446.     // No embedded frames
  2447. }
  2448.  
  2449. //----------------------------------------------------------------------------------------
  2450. // FW_CFrame::PrivCreateSubViewsFromStream
  2451. //----------------------------------------------------------------------------------------
  2452.  
  2453. void FW_CFrame::PrivCreateSubViewsFromStream(Environment* ev, FW_CReadableStream& stream)
  2454. {
  2455.     FW_PREREGISTER_RUNTIME_OBJECT(stream, 
  2456.                                 this, 
  2457.                                 FW_kPreregisteredFrameObject);
  2458.                                 
  2459.     FW_CSuperView::PrivCreateSubViewsFromStream(ev, stream);
  2460.  
  2461.     short count;
  2462.     stream >> count;
  2463.     FW_ASSERT(count >= 0);
  2464.     FW_ASSERT(count <= 1);
  2465.     if (count == 1)
  2466.     {
  2467.         FW_CPrivBaseScroller* scroller;
  2468.         FW_READ_DYNAMIC_OBJECT(stream, &scroller, FW_CPrivBaseScroller);
  2469.         
  2470.         // [HLX] I am always dealing with a FW_CScroller
  2471.         AdoptScroller(ev, (FW_CScroller*)scroller);    
  2472.     }
  2473. }
  2474.  
  2475. //----------------------------------------------------------------------------------------
  2476. // FW_CFrame::PrivButtonAttached
  2477. //----------------------------------------------------------------------------------------
  2478.  
  2479. void FW_CFrame::PrivButtonAttached(Environment* ev, FW_CButton* button)
  2480. {
  2481. FW_UNUSED(ev);
  2482. FW_UNUSED(button);
  2483.     // Nothing to do look at FW_CDialogFrame
  2484. }
  2485.  
  2486. //----------------------------------------------------------------------------------------
  2487. // FW_CFrame::PrivCreateViewAs
  2488. //----------------------------------------------------------------------------------------
  2489. // Call in places where the viewas object might not be yet created 
  2490.  
  2491. void FW_CFrame::PrivCreateViewAs(Environment* ev)
  2492. {
  2493.     ODTypeToken viewType = GetViewType(ev);
  2494.     if (viewType != FW_CPart::fgViewAsFrameToken && fViewAs == NULL)
  2495.     {
  2496.         fViewAs = fPresentation->PrivAcquireViewAs(ev, this, viewType);
  2497.     }
  2498. }
  2499.  
  2500. //----------------------------------------------------------------------------------------
  2501. //     FW_CFrame::PrivInstantiateViews
  2502. //----------------------------------------------------------------------------------------
  2503.         
  2504. void FW_CFrame::PrivInstantiateViews(Environment* ev)
  2505. {
  2506.     FW_ResourceID resourceID = GetPresentation(ev)->GetViewResourceID(ev, IsRoot(ev));
  2507.     if (resourceID != 0)        
  2508.         CreateSubViewsFromResource(ev, resourceID);    // Automatic view creation from resources
  2509.     else
  2510.         PrivCreateSubViews(ev);    // Manual view creation
  2511.     
  2512.     fSubViewsCreated = TRUE;
  2513. }
  2514.         
  2515. //----------------------------------------------------------------------------------------
  2516. //     FW_CFrame::PrivGetInfoString
  2517. //----------------------------------------------------------------------------------------
  2518. FW_Boolean FW_CFrame::PrivGetInfoString(Environment* ev, FW_CSelection* selection, FW_CString& infoString)
  2519. {
  2520.     FW_Boolean gotInfo = false;
  2521.  
  2522.     //--- Check for Link Info ---
  2523.     if (GetPart(ev)->GetLinkManager(ev) != NULL)
  2524.         gotInfo = GetPart(ev)->GetLinkManager(ev)->GetLinkInfoString(ev, infoString);
  2525.     if (gotInfo) return true;
  2526.  
  2527.     //--- Check for Selection Info ---
  2528.     if (selection && !selection->IsEmpty(ev))
  2529.         gotInfo = selection->GetSelectionInfoString(ev, infoString);
  2530.  
  2531.     return gotInfo;
  2532. }
  2533.